:root {
  --accent: #A100FF;
  --accent-dark: #6B00AA;
  --accent-light: #F3E6FF;
  --bg: #F4F4F4;
  --surface: #FFFFFF;
  --sidebar-bg: #160025;
  --sidebar-text: #E0E0E0;
  --sidebar-muted: #888;
  --sidebar-hover: rgba(161, 0, 255, 0.18);
  --sidebar-active: rgba(161, 0, 255, 0.35);
  --text: #111;
  --text-muted: #666;
  --border: #E0E0E0;
  --danger: #D32F2F;
  --radius: 10px;
}

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

body {
  font-family: 'Segoe UI', 'Hiragino Sans', 'Meiryo', sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ─── レイアウト ─── */
.app {
  display: flex;
  height: 100vh;
}

/* ─── サイドバー ─── */
.sidebar {
  width: 230px;
  min-width: 230px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-logo {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.logo-mark {
  color: var(--accent);
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.logo-text {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.sidebar-add {
  padding: 12px 10px 8px;
  flex-shrink: 0;
}

.btn-add-persona {
  width: 100%;
  background: rgba(161, 0, 255, 0.2);
  border: 1.5px dashed rgba(161, 0, 255, 0.5);
  color: #D4A0FF;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s;
}

.btn-add-persona:hover {
  background: rgba(161, 0, 255, 0.35);
  border-color: var(--accent);
  color: #fff;
}

.btn-add-icon {
  font-size: 16px;
  line-height: 1;
}

.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0 12px;
}

.section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sidebar-muted);
  padding: 8px 16px 6px;
}

.persona-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
}

.persona-item {
  padding: 9px 10px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--sidebar-text);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 9px;
  transition: background 0.15s;
}

.persona-item:hover { background: var(--sidebar-hover); }
.persona-item.active { background: var(--sidebar-active); color: #fff; }

.persona-avatar-sm {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.persona-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── メインエリア ─── */
.main {
  flex: 1;
  overflow: hidden;
}

.chat-area {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ─── プレースホルダー ─── */
.chat-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.placeholder-inner {
  text-align: center;
  max-width: 380px;
}

.placeholder-icon {
  font-size: 2.8rem;
  margin-bottom: 16px;
  line-height: 1;
}

.placeholder-inner h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 10px;
}

.placeholder-inner p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 24px;
}

/* ─── チャットヘッダー ─── */
.chat-header {
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-persona-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-persona-name {
  font-size: 15px;
  font-weight: 700;
}

.chat-persona-role {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ─── メッセージ ─── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--bg);
}

.message {
  display: flex;
  gap: 10px;
  max-width: 78%;
}

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

.message.assistant {
  align-self: flex-start;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 18px;
}

.message.user .message-avatar {
  background: #444;
}

.message-inner { display: flex; flex-direction: column; min-width: 0; }

.message-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
  padding-left: 2px;
}

.message-bubble {
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.message.user .message-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* 入力中アニメーション */
.typing-indicator {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 14px 16px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #bbb;
  animation: typing 1.2s infinite;
}

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

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ─── 入力エリア ─── */
.input-area {
  padding: 10px 20px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.input-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

/* 添付プレビュー */
.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 0 2px;
}

.att-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f0e8ff;
  border: 1px solid #d4b8ff;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  color: #5a00a0;
}

.att-thumb { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; }
.att-icon { font-size: 16px; }
.att-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-remove { background: none; border: none; cursor: pointer; color: #999; padding: 0 2px; font-size: 12px; }
.att-remove:hover { color: #c00; }

/* 添付ボタン */
.btn-attach {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #888;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
.btn-attach:hover { border-color: var(--accent); color: var(--accent); }

/* チャット内添付表示 */
.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.msg-att-image { max-width: 200px; max-height: 160px; border-radius: 8px; object-fit: cover; cursor: pointer; }
.msg-att-chip {
  background: #f0e8ff;
  border: 1px solid #d4b8ff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  color: #5a00a0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 220px;
  transition: background 0.15s;
}
.msg-att-chip:hover { background: #e2d0ff; }
.msg-att-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ファイルプレビューモーダル */
.modal-preview {
  width: 780px;
  max-width: 95vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.file-preview-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}
.file-preview-body pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'Segoe UI', sans-serif;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  margin: 0;
}
.file-preview-body img {
  max-width: 100%;
  border-radius: 8px;
}

/* ファイルアクションドロップダウン */
.file-action-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  z-index: 2000;
  min-width: 180px;
  overflow: hidden;
}
.file-action-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: background 0.1s;
}
.file-action-item:hover { background: var(--hover); }
.file-action-item + .file-action-item { border-top: 1px solid var(--border); }

.message-input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.5;
  max-height: 140px;
  overflow-y: auto;
}

.message-input:focus { border-color: var(--accent); }

/* ─── ボタン ─── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { background: #ccc; cursor: not-allowed; }

.btn-outline {
  background: none;
  color: var(--accent);
  border: 1.5px solid var(--accent);
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-outline:hover { background: var(--accent-light); }

.btn-ghost {
  background: none;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-ghost:hover { background: var(--bg); }

.btn-danger {
  background: none;
  color: var(--danger);
  border: 1.5px solid var(--danger);
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.btn-send:hover { background: var(--accent-dark); }
.btn-send:disabled { background: #ccc; cursor: not-allowed; }

.btn-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}
.btn-close:hover { background: var(--bg); color: var(--text); }

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

.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-large { width: 580px; }

.modal-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal-header h3 { font-size: 16px; font-weight: 700; }

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-shrink: 0;
}

/* ─── フォーム ─── */
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.form-hint { font-weight: 400; color: var(--text-muted); font-size: 12px; }

.form-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--accent); }

.form-textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  font-family: 'Consolas', 'Courier New', monospace;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.6;
  min-height: 220px;
}
.form-textarea:focus { border-color: var(--accent); }

/* ─── ビルドステータス ─── */
.build-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--accent-light);
  border-radius: 8px;
  margin-top: 14px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 600;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(161,0,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

/* ─── プロファイル ─── */
.profile-section { margin-bottom: 16px; }

.profile-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.profile-section-body {
  font-size: 14px;
  line-height: 1.65;
}

.profile-tag {
  display: inline-block;
  background: var(--accent-light);
  color: var(--accent-dark);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin: 3px 4px 3px 0;
}

.raw-data-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  font-family: monospace;
  max-height: 120px;
  overflow-y: auto;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ─── タイムスタンプ ─── */
.msg-timestamp {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
  opacity: 0.75;
}
.message.user .msg-timestamp {
  text-align: right;
}

/* ─── スクロールバー ─── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ddd; border-radius: 3px; }

/* ─── 会話履歴 ─── */
.history-list {
  max-height: 420px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 8px;
}

.history-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 32px 0;
}

.history-date-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 0 2px;
}

.history-session-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.history-session-item:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.history-session-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.history-session-info {
  flex: 1;
  min-width: 0;
}

.history-session-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-session-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── セッション詳細 ─── */
.session-detail-body {
  max-height: 500px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0 8px;
}

.session-msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.session-msg.user { flex-direction: row-reverse; }

.session-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.session-msg.user .session-msg-avatar {
  background: #555;
}

.session-msg-bubble {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.session-msg.assistant .session-msg-bubble {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
}

.session-msg.user .session-msg-bubble {
  background: var(--accent);
  color: #fff;
}
