:root {
  --bg-deep: #080a0f;
  --bg-main: #0d111a;
  --bg-surface: #141b26;
  --bg-panel: #1a2233;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(56, 189, 248, 0.5);

  --accent-cyan: #38bdf8;
  --accent-cyan-glow: rgba(56, 189, 248, 0.3);
  --accent-indigo: #818cf8;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Meiryo", sans-serif;
  --font-mono: "Fira Code", "Consolas", monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font-sans);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ==================== ヘッダー ==================== */
.app-header {
  height: 54px;
  background: var(--bg-main);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  user-select: none;
  z-index: 100;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  font-size: 1.15rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-indigo));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-icon {
  font-size: 1.3rem;
  color: var(--accent-cyan);
}

.badge-tag {
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.25);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.dot-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 10px var(--accent-green);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.header-btn:hover {
  background: var(--bg-panel);
  border-color: var(--accent-cyan);
}

.btn-danger-glow {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.btn-danger-glow:hover {
  background: #dc2626 !important;
  color: #fff !important;
  border-color: #ef4444 !important;
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.5);
}

.btn-artifacts-toggle {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.3);
  color: var(--accent-cyan);
}

/* ==================== メインレイアウト ==================== */
.main-layout {
  flex: 1;
  display: flex;
  height: calc(100vh - 54px);
  height: calc(100dvh - 54px);
  overflow: hidden;
  position: relative;
}

/* ==================== チャットビューポート (中央メイン) ==================== */
.chat-viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
  background: radial-gradient(circle at 50% 0%, #111827 0%, var(--bg-deep) 70%);
}

.chat-timeline {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px 180px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  scroll-behavior: smooth;
  overscroll-behavior-y: contain;
}

/* メッセージアイテム */
.message-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 85%;
  animation: fadeIn 0.25s ease-out;
}

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

.message-user {
  align-self: flex-end;
}

.message-user .message-bubble {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #ffffff;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 4px 15px rgba(37, 99, 235, 0.25);
}

.message-assistant {
  align-self: flex-start;
  max-width: 92%;
}

.message-assistant .message-bubble {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.message-bubble {
  padding: 16px 20px;
  font-size: 0.95rem;
  line-height: 1.7;
  word-break: break-word;
  white-space: normal;
}

.message-user .message-bubble {
  white-space: pre-wrap;
}

.message-bubble p {
  margin: 0 0 0.8em 0;
  line-height: 1.7;
}

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

.message-bubble h2, .message-bubble h3, .message-bubble h4 {
  color: var(--accent-cyan);
  margin: 1.2em 0 0.5em 0;
  font-weight: 700;
  line-height: 1.4;
}

.message-bubble h2 { font-size: 1.2rem; }
.message-bubble h3 { font-size: 1.1rem; }
.message-bubble h4 { font-size: 1.0rem; }

.message-bubble h2:first-child, .message-bubble h3:first-child, .message-bubble h4:first-child {
  margin-top: 0;
}

.chat-markdown-list {
  margin: 0.5em 0 0.8em 0;
  padding-left: 20px;
}

.chat-markdown-list li {
  margin-bottom: 0.4em;
  line-height: 1.65;
  color: #e2e8f0;
}

.message-bubble strong {
  color: #fff;
  font-weight: 700;
}

.message-bubble em {
  color: #93c5fd;
  font-style: italic;
}

.message-bubble blockquote {
  margin: 0.8em 0;
  padding: 8px 14px;
  border-left: 3px solid var(--accent-cyan);
  background: rgba(56, 189, 248, 0.06);
  color: #cbd5e1;
  border-radius: 0 8px 8px 0;
  font-size: 0.92rem;
}

.chat-divider {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 1.2em 0;
}

.chat-para-spacer {
  height: 0.4em;
}

.inline-code {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86rem;
  color: #38bdf8;
}

.code-block {
  background: #090d16;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 12px;
  margin: 0.8em 0;
  overflow-x: auto;
}

.action-block-pill {
  font-size: 0.75rem;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.25);
  color: var(--accent-cyan);
  padding: 4px 10px;
  border-radius: 6px;
  display: inline-block;
  margin: 4px 0;
}

/* インラインメディア（Krea 2画像 / H3動画）プレビューカード */
.inline-media-card {
  margin-top: 14px;
  background: var(--bg-main);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  transition: border-color 0.2s;
}

.inline-media-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-media-badge {
  font-size: 0.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #fff;
  padding: 3px 8px;
  border-radius: 6px;
}

.inline-video-card .inline-media-badge {
  background: linear-gradient(135deg, #8b5cf6, #d946ef);
}

.inline-media-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
}

.inline-media-preview-container {
  width: 100%;
  display: flex;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 10px;
  overflow: hidden;
  min-height: 120px;
  align-items: center;
}

.chat-inline-media-img {
  width: 100%;
  max-height: 480px;
  object-fit: contain;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.2s;
}

.chat-inline-media-img:hover {
  transform: scale(1.01);
}

.chat-inline-media-video {
  width: 100%;
  max-height: 400px;
  border-radius: 10px;
  background: #000;
}

.message-meta {
  font-size: 0.72rem;
  color: var(--text-dim);
  padding: 0 4px;
}

/* メッセージ内メディア表示 */
.chat-image-attachment {
  max-width: 320px;
  max-height: 240px;
  border-radius: 10px;
  margin-top: 10px;
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: transform 0.2s;
  display: block;
}

.chat-image-attachment:hover {
  transform: scale(1.02);
}

.chat-audio-player {
  margin-top: 10px;
  width: 100%;
  max-width: 340px;
  border-radius: 8px;
}

.chat-video-player {
  margin-top: 10px;
  max-width: 400px;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
}

/* アクション・アーティファクト通知カード */
.artifact-notify-card {
  margin-top: 12px;
  padding: 12px 14px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.notify-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent-cyan);
}

.btn-open-artifact {
  background: var(--accent-cyan);
  color: #000;
  font-weight: 700;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.78rem;
  cursor: pointer;
}

/* エージェントアクティビティバナー */
.agent-activity-banner {
  position: absolute;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(56, 189, 248, 0.4);
  box-shadow: 0 4px 25px rgba(0, 0, 0, 0.6);
  padding: 10px 18px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 50;
  animation: fadeIn 0.2s ease-out;
}

.activity-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(56, 189, 248, 0.3);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.activity-text {
  display: flex;
  flex-direction: column;
}

.activity-step {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-cyan);
}

.activity-detail {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ==================== Gemini風 フローティング入力バー ==================== */
.chat-input-container {
  position: absolute;
  bottom: 20px;
  left: 0;
  right: 0;
  max-width: 860px;
  width: calc(100% - 40px);
  margin: 0 auto;
  z-index: 60;
}

.attached-image-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px dashed var(--accent-cyan);
  border-radius: 10px;
  margin-bottom: 8px;
  backdrop-filter: blur(8px);
}

.attached-image-preview img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
}

.preview-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1;
}

#attached-img-name {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.btn-remove-img {
  background: transparent;
  border: none;
  color: #ef4444;
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
}

.input-card {
  background: rgba(20, 27, 38, 0.85);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-card:focus-within {
  border-color: var(--accent-cyan);
  box-shadow: 0 10px 40px rgba(56, 189, 248, 0.25);
}

.main-textarea {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
  resize: none;
  min-height: 48px;
  max-height: 160px;
  outline: none;
}

.input-controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 8px;
}

.controls-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tool-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}

.tool-btn:hover {
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

.mode-pill-selector, .model-pill-selector {
  display: flex;
  background: var(--bg-deep);
  border-radius: 8px;
  padding: 2px;
  border: 1px solid var(--border-subtle);
  overflow-x: auto;
  scrollbar-width: none;
  gap: 2px;
}
.mode-pill-selector::-webkit-scrollbar {
  display: none;
}

.mode-pill-btn, .model-pill-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.mode-pill-btn:hover, .model-pill-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.mode-pill-btn.active, .model-pill-btn.active {
  background: var(--accent-cyan);
  color: #000;
  font-weight: 700;
  box-shadow: 0 1px 6px rgba(56, 189, 248, 0.3);
}

.mode-pill-btn[data-mode="deep_research"].active {
  background: linear-gradient(135deg, #a855f7, #c084fc);
  color: #fff;
}

.search-check-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
}

.controls-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.keyboard-tip {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.send-action-btn {
  background: linear-gradient(135deg, #0284c7, var(--accent-cyan));
  color: #000;
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 15px var(--accent-cyan-glow);
  transition: transform 0.1s, opacity 0.2s;
}

.send-action-btn:hover {
  opacity: 0.95;
}

.send-action-btn:active {
  transform: scale(0.96);
}

/* ==================== 成果物 (Artifacts) サイドパネル ==================== */
.artifacts-pane {
  width: 520px;
  background: var(--bg-main);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  transition: margin-right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  margin-right: 0;
  position: relative;
  z-index: 80;
}

.artifacts-pane.closed {
  margin-right: -520px;
}

.artifacts-header {
  height: 48px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
}

.artifacts-tabs {
  display: flex;
  gap: 4px;
}

.tab-item {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.tab-item:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.tab-item.active {
  color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.12);
}

.btn-close-pane {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
}

.artifact-tab-content {
  flex: 1;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.artifact-tab-content.active {
  display: flex;
}

/* ① アプリプレビュー & コード */
.preview-actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.78rem;
}

.preview-address-bar {
  color: var(--text-muted);
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  cursor: pointer;
}

.live-preview-box {
  flex: 1.2;
  background: #fff;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
}

.preview-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.workspace-code-tray {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #090d16;
}

.tray-header {
  height: 32px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  font-size: 0.75rem;
}

.code-editor-wrapper {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.file-tree-bar {
  width: 140px;
  background: var(--bg-deep);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  font-size: 0.78rem;
  padding: 6px 0;
}

.tree-file-node {
  padding: 5px 10px;
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
}

.tree-file-node.active {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  font-weight: 600;
}

.code-viewer-textarea {
  flex: 1;
  background: transparent;
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 10px;
  border: none;
  resize: none;
  outline: none;
  line-height: 1.5;
  white-space: pre;
}

/* ② 生成メディアギャラリー */
.media-gallery-header {
  padding: 10px 14px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-cyan);
}

.media-gallery-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty-media-hint {
  color: var(--text-muted);
  font-size: 0.88rem;
  text-align: center;
  margin-top: 40px;
  line-height: 1.6;
  padding: 20px;
}

.media-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.media-card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.media-preview-container {
  display: flex;
  justify-content: center;
  background: var(--bg-deep);
  border-radius: 8px;
  padding: 8px;
}

.media-preview-img {
  max-width: 100%;
  max-height: 200px;
  border-radius: 6px;
}

.media-preview-video {
  width: 100%;
  max-height: 220px;
  border-radius: 6px;
}

.media-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ③ APK & スマホ */
.apk-hub-wrapper {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hub-block {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 16px;
}

.hub-block h3 {
  font-size: 0.92rem;
  color: var(--accent-cyan);
  margin-bottom: 6px;
}

.hub-block p {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.btn-apk-build-action {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
  background: var(--bg-deep);
  border-radius: 8px;
  margin-top: 10px;
}

.qr-image {
  width: 160px;
  height: 160px;
  border-radius: 6px;
}

.qr-label {
  font-size: 0.78rem;
  color: var(--accent-cyan);
  margin-top: 6px;
  font-weight: 600;
}

.download-pill-link {
  display: inline-block;
  margin-top: 10px;
  padding: 8px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  color: var(--accent-cyan);
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
}

/* ④ ターミナルログ */
.terminal-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #04060a;
}

.terminal-logs {
  flex: 1;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--accent-cyan);
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.terminal-cmd-bar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
}

.terminal-cmd-bar span {
  color: var(--accent-cyan);
  margin-right: 8px;
}

.terminal-cmd-bar input {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  outline: none;
}

/* モーダル */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.active { display: flex; }

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--accent-cyan);
  border-radius: 14px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  text-align: center;
}

.modal-qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 14px;
}

.modal-qr-img {
  width: 170px;
  height: 170px;
  border-radius: 8px;
}

.modal-url-text {
  font-size: 0.85rem;
  color: var(--accent-cyan);
  margin-top: 8px;
  font-weight: 700;
}

/* ==================== レスポンシブ (スマホ & タブレット表示) ==================== */
@media (max-width: 900px) {
  .artifacts-pane {
    position: fixed;
    top: 50px;
    right: 0;
    bottom: 0;
    width: 100%;
    z-index: 200;
  }
  .artifacts-pane.closed {
    margin-right: -100%;
  }
}

@media (max-width: 768px) {
  /* ヘッダーのコンパクト化 (1行に完全収容) */
  .app-header {
    height: 50px;
    padding: 0 10px;
    gap: 6px;
  }
  .main-layout {
    height: calc(100vh - 50px);
    height: calc(100dvh - 50px);
  }
  .brand-section {
    gap: 6px;
    min-width: 0;
    flex-shrink: 1;
  }
  .brand-logo {
    font-size: 0.95rem;
    gap: 4px;
    white-space: nowrap;
  }
  .brand-name {
    font-size: 0.95rem;
  }
  .badge-tag {
    display: none !important;
  }
  .header-center {
    display: none !important;
  }
  .header-actions {
    gap: 5px;
    flex-shrink: 0;
  }
  .header-btn {
    padding: 5px 8px;
    font-size: 0.74rem;
    gap: 4px;
    white-space: nowrap;
  }
  #btn-show-mobile-qr {
    display: none !important;
  }
  #btn-emergency-stop {
    padding: 5px 8px;
    font-size: 0.74rem;
    font-weight: 700;
  }
  #btn-toggle-artifacts {
    padding: 5px 8px;
  }

  /* チャットタイムライン (入力バーに隠れない十分な下部余白: 240px) */
  .chat-timeline {
    padding: 12px 10px 240px 10px;
    gap: 14px;
  }
  .message-item {
    max-width: 96%;
  }
  .message-bubble {
    padding: 10px 14px;
    font-size: 0.9rem;
    line-height: 1.55;
    border-radius: 14px;
  }

  /* フローティング入力バー (画面下端へのフィットとボタン配置最適化) */
  .chat-input-container {
    bottom: max(6px, env(safe-area-inset-bottom, 6px));
    left: 8px;
    right: 8px;
    width: calc(100% - 16px);
    max-width: none;
  }
  .input-card {
    padding: 8px 10px;
    border-radius: 14px;
    gap: 6px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.85);
  }
  .main-textarea {
    font-size: 0.92rem;
    min-height: 38px;
    max-height: 100px;
  }
  .keyboard-tip {
    display: none !important;
  }
  .input-controls-row {
    padding-top: 6px;
    gap: 6px;
    align-items: center;
  }
  .controls-left {
    flex: 1;
    min-width: 0;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .controls-left::-webkit-scrollbar {
    display: none;
  }
  .tool-btn {
    padding: 4px 8px;
    font-size: 0.72rem;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .model-pill-selector {
    flex-shrink: 0;
  }
  .model-pill-btn {
    padding: 3px 6px;
    font-size: 0.68rem;
    white-space: nowrap;
  }
  .search-check-label {
    flex-shrink: 0;
    font-size: 0.72rem;
    white-space: nowrap;
    gap: 4px;
  }
  .controls-right {
    flex-shrink: 0;
  }
  .send-action-btn {
    padding: 5px 12px;
    font-size: 0.8rem;
    height: 32px;
  }
}

/* ==================== 会話一覧スライドイン・ドロワー ==================== */
.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 250;
  display: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.drawer-overlay.active {
  display: block;
  opacity: 1;
}

.sessions-drawer {
  position: fixed;
  top: 0;
  left: -340px;
  width: 320px;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  box-shadow: 4px 0 25px rgba(0, 0, 0, 0.7);
  z-index: 260;
  display: flex;
  flex-direction: column;
  transition: left 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.sessions-drawer.active {
  left: 0;
}

.drawer-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  color: var(--accent-cyan);
}

.drawer-close-btn, .modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s;
}

.drawer-close-btn:hover, .modal-close-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.drawer-actions-box {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.drawer-action-btn {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-main);
  color: var(--text-main);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-new-session {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.2), rgba(37, 99, 235, 0.3));
  border-color: rgba(56, 189, 248, 0.4);
  color: #fff;
}

.btn-new-session:hover {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.35), rgba(37, 99, 235, 0.45));
  box-shadow: 0 0 15px rgba(56, 189, 248, 0.3);
}

.sessions-scroll-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: all 0.2s;
}

.session-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.session-item.active {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.4);
}

.session-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.session-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item.active .session-title {
  color: var(--accent-cyan);
}

.session-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--text-dim);
}

.session-delete-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 6px;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
}

.session-delete-btn:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
}

/* ==================== 記憶設定（メモリー）モーダル ==================== */
.memory-modal-card {
  max-width: 520px;
  width: 90%;
  padding: 20px 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

.modal-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.memory-list-box {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  padding-right: 4px;
}

.memory-item-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
}

.memory-item-text {
  font-size: 0.86rem;
  color: var(--text-main);
  line-height: 1.5;
  flex: 1;
  word-break: break-word;
}

.memory-item-delete {
  background: transparent;
  border: none;
  color: #f87171;
  font-size: 0.78rem;
  padding: 2px 6px;
  cursor: pointer;
  border-radius: 4px;
  white-space: nowrap;
  transition: all 0.2s;
}

.memory-item-delete:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.memory-add-form {
  display: flex;
  gap: 8px;
}

#memory-input {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-main);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-main);
  font-size: 0.86rem;
  outline: none;
}

#memory-input:focus {
  border-color: var(--accent-cyan);
}

.memory-add-btn {
  background: var(--accent-cyan);
  color: #000;
  font-weight: 700;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.memory-add-btn:hover {
  background: #7dd3fc;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

/* ==================== 参照ソース (Web情報) タブ ==================== */
#tab-sources {
  display: none;
  flex-direction: column;
  height: calc(100% - 48px);
  background: var(--bg-surface);
  overflow: hidden;
}

#tab-sources.active {
  display: flex;
}

.sources-panel-header {
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.7);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sources-title-box {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sources-icon {
  font-size: 1.3rem;
}

.sources-title-text {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
}

.sources-sub-text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sources-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-sources-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 40px;
  line-height: 1.6;
}

.source-card {
  background: var(--bg-main);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 14px;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.source-card:hover {
  border-color: var(--accent-cyan);
  box-shadow: 0 4px 16px rgba(56, 189, 248, 0.1);
  transform: translateY(-1px);
}

.source-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.source-card-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-cyan);
  text-decoration: none;
  line-height: 1.4;
  word-break: break-word;
}

.source-card-title:hover {
  text-decoration: underline;
}

.source-badge {
  font-size: 0.7rem;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  white-space: nowrap;
}

.source-card-url {
  font-size: 0.74rem;
  color: var(--text-muted);
  word-break: break-all;
  display: flex;
  align-items: center;
  gap: 4px;
}

.source-card-snippet {
  font-size: 0.82rem;
  color: #cbd5e1;
  line-height: 1.5;
  background: rgba(255, 255, 255, 0.02);
  padding: 8px;
  border-radius: 6px;
  border-left: 2px solid var(--accent-cyan);
}

.source-open-btn {
  align-self: flex-start;
  margin-top: 4px;
  font-size: 0.75rem;
  padding: 4px 10px;
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 6px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}

.source-open-btn:hover {
  background: var(--accent-cyan);
  color: #000;
}

/* チャット内参照リンクトリガーボタン */
.chat-sources-trigger {
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.2s;
}

.chat-sources-trigger:hover {
  background: rgba(56, 189, 248, 0.18);
  border-color: var(--accent-cyan);
}

.chat-sources-trigger-text {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-sources-trigger-arrow {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ==================== 思考停止 (Stop) ボタン ==================== */
.send-action-btn.btn-stopping {
  background: linear-gradient(135deg, #ef4444, #dc2626) !important;
  color: #fff !important;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4) !important;
  animation: pulse-stopping 1.5s infinite;
}

@keyframes pulse-stopping {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.98); opacity: 0.85; }
  100% { transform: scale(1); opacity: 1; }
}

.btn-stop-agent {
  margin-left: auto;
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.6);
  color: #fca5a5;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-stop-agent:hover {
  background: rgba(239, 68, 68, 0.8);
  color: #fff;
  border-color: #ef4444;
}

/* ==================== Gemini 3.8 Flash Extended スタイル思考プロセス ==================== */
details.thought-process {
  margin-bottom: 12px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.2s;
}

details.thought-process:hover {
  border-color: rgba(56, 189, 248, 0.4);
}

details.thought-process summary {
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-cyan);
  cursor: pointer;
  background: rgba(30, 41, 59, 0.5);
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
  outline: none;
  transition: background 0.2s;
}

details.thought-process summary:hover {
  background: rgba(56, 189, 248, 0.12);
}

details.thought-process p,
details.thought-process ul,
details.thought-process ol {
  padding: 8px 14px;
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--text-secondary);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

details.thought-process strong {
  color: var(--text-primary);
}


