/* =========================================
   ベースリセット & 共通設定
   ========================================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  overflow-x: hidden; /* 横スクロール禁止 */
}

/* 専属あいシステム全体のベースレイアウト */
body.app {
  margin: 0;
  background: #020617;
  color: #e5e7eb;
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Helvetica Neue",
    "Yu Gothic", YuGothic, "Meiryo",
    sans-serif;

  display: flex;
  flex-direction: column; /* 上:ヘッダー / 下:コンテンツ */
  height: 100dvh;         /* 画面高さいっぱい（モバイル対応） */
  overflow: hidden;       /* ページ全体はスクロールさせない */
}

/* iPhone キーボードズーム防止ライン */
input,
textarea,
button {
  font-size: 16px;
}

/* =========================================
   ヘッダー
   ========================================= */
.topbar {
  flex: 0 0 auto;
  height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #020617;
  border-bottom: 1px solid #1f2937;

  /* 画面上に固定 */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.logo {
  font-weight: 700;
  font-size: 16px;
}

.topbar-title {
  margin-left: 8px;
}

.topbar-link {
  color: #9ca3af;
  text-decoration: none;
  margin-left: 12px;
  font-size: 14px;
}

.topbar-link:hover {
  color: #e5e7eb;
}

/* =========================================
   チャット画面レイアウト
   ========================================= */

/* ヘッダーの下に来るチャット全体のコンテナ */
.layout-chat {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;  /* 上:タブ + ログ / 下:入力欄 */
  min-height: 0;
  max-width: 100%;

  /* 固定ヘッダーぶんだけ下にずらす */
  padding-top: 56px;
  height: calc(100dvh - 56px);
}

/* 人格切り替えタブの行 */
.persona-tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px 16px 4px;
  margin: 0 0 4px 0;
  border-bottom: 1px solid #1f2937;
  max-width: 100%;
  overflow-x: auto;  /* タブが増えたら横スクロール */
}

/* タブのボタン */
.persona-tab {
  background: #0b1120;
  border-radius: 999px;
  border: 1px solid #374151;
  padding: 4px 12px;
  font-size: 14px;
  color: #e5e7eb;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

/* 選択中タブ */
.persona-tab.active {
  background: #4f46e5;
  border-color: #4f46e5;
  color: #e5e7eb;
}

/* メッセージ一覧エリア（ここだけスクロール） */
.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px;
  max-width: 100%;
}

/* 入力エリア（常に一番下） */
.chat-input-area {
  flex: 0 0 auto;
  border-top: 1px solid #1f2937;
  padding: 8px 10px 12px;
  background: #020617;
  max-width: 100%;
}

.chat-input-main {
  max-width: 100%;
}

.chat-textarea {
  width: 100%;
  min-height: 52px;
  resize: none;
  border: none;
  outline: none;
  padding: 6px 10px;
  font-size: 16px;   /* ズーム防止ライン */
  line-height: 1.4;
  background: transparent;
  color: #e5e7eb;
}

.chat-input-footer {
  display: flex;
  align-items: center;
  margin-top: 6px;
  max-width: 100%;
}

/* 送信ボタン（右下に丸く配置） */
.chat-send,
.btn.primary {
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  background: #4f46e5;
  color: #ffffff;
  font-size: 16px;
}

.chat-send {
  margin-left: auto;
}

/* クリップアイコンなど */
.file-label {
  cursor: pointer;
}

.file-input {
  display: none;
}

/* =========================================
   メッセージ表示（吹き出し）
   ========================================= */

.message-row {
  display: flex;
  margin-bottom: 8px;
  max-width: 100%;
}

.message-row.from-user {
  justify-content: flex-end;
}

.message-row.from-assistant {
  justify-content: flex-start;
}

.message-bubble {
  padding: 10px 12px;
  border-radius: 16px;
  background: #111827;
  max-width: 100%;
}

.message-bubble pre {
  margin-top: 6px;
  padding: 8px;
  background: #020617;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre;
}

.code-block-wrap {
  position: relative;
  margin-top: 8px;
  display: inline-block;
  width: 100%;
}

.code-block {
  margin-top: 6px;
  padding: 8px;
  background: #020617;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre;
}

/* ボタンがかぶらないように上だけ少し余白広め */
pre.code-block {
  margin: 0;
  padding: 10px;
  padding-top: 26px;
  background: #020617;
  color: #e5e7eb;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre;
}

.code-copy-inline-btn {
  position: absolute;
  top: 4px;
  right: 8px;
  padding: 2px 8px;
  font-size: 10px;
  border: none;
  border-radius: 4px;
  background: #1f2937;
  color: #e5e7eb;
  cursor: pointer;
}

.from-user .message-bubble {
  background: #4f46e5;
}

.message-meta {
  font-size: 11px;
  color: #9ca3af;
  margin-bottom: 4px;
}

.message-text {
  margin-top: 4px;
  white-space: pre-wrap;
  word-break: break-word; /* 長文も折り返す */
  color: #e5e7eb;
}

.message-image {
  max-width: 200px;
  border-radius: 8px;
  margin-top: 6px;
}

/* タイムスタンプ（吹き出し下） */
.message-time {
  margin-top: 4px;
  font-size: 11px;
  color: #9ca3af;
  text-align: right;
  opacity: 0.7;
}


.code-block-wrap {
  margin-top: 8px;
}

.code-block-label {
  font-size: 11px;
  color: #9ca3af;
  margin-bottom: 4px;
}

.code-block {
  font-family: ui-monospace, SFMonoText, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
  background: #020617;
  border-radius: 8px;
  padding: 8px;
  overflow-x: auto;
  white-space: pre;      /* インデント完全維持 */
}

.code-copy-btn {
  position: absolute;
  top: 6px;
  right: 10px;
  padding: 2px 8px;
  font-size: 10px;
  background: rgba(15, 23, 42, 0.85); /* ちょい暗めで控えめ */
  color: #e5e7eb;
  border: 1px solid #4b5563;
  border-radius: 999px;
  cursor: pointer;
  opacity: 0.6;
}

.code-copy-btn:hover {
  opacity: 1;
}


/* =========================================
   ログインカードなどの汎用コンポーネント
   ========================================= */

.app-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.card {
  background: #111827;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.card-narrow {
  width: 100%;
  max-width: 400px;
}

.title {
  margin: 0 0 4px;
  font-size: 24px;
}

.subtitle {
  margin: 0 0 20px;
  color: #9ca3af;
}

.input {
  width: 100%;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid #374151;
  background: #020617;
  color: #e5e7eb;
  padding: 6px 10px;
  outline: none;
}

/* =========================================
   管理画面用レイアウト
   ========================================= */

.layout-admin .grid {
  display: grid;
  gap: 16px;
  padding: 16px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.card-title {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 16px;
}

.metric {
  margin: 2px 0;
  font-size: 14px;
}

.card-wide {
  grid-column: 1 / -1;
}

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

.notification-item {
  font-size: 14px;
  padding: 4px 0;
  border-bottom: 1px solid #1f2937;
}

/* 汎用 */
.error-text {
  color: #f97373;
  margin-top: 8px;
  font-size: 13px;
}

.hidden {
  display: none;
}
