:root {
  --ink: #18212f;
  --muted: #667085;
  --line: #dde3ea;
  --panel: #ffffff;
  --bg: #f6f8fb;
  --primary: #2557a7;
  --ai-green: #10a37f;
}

body {
  background: var(--bg);
  color: var(--ink);
}

.navbar-brand { color: var(--ink); }

/* ── 一般レイアウト ──────────────────────────────────────────────── */
.page-heading {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.page-heading h1 { font-size: 28px; margin: 0 0 4px; }
.page-heading p  { color: var(--muted); margin: 0; }

.panel, .metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}
.panel h2 { font-size: 18px; margin-bottom: 16px; }

.metric-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.metric span   { color: var(--muted); display: block; font-size: 13px; }
.metric strong { display: block; font-size: 30px; line-height: 1.2; margin-top: 8px; }

.list-item            { border-top: 1px solid var(--line); padding: 14px 0; }
.list-item:first-of-type { border-top: 0; padding-top: 0; }
.list-item p          { white-space: pre-wrap; }

.tall { min-height: 180px; }

.result pre {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
  white-space: pre-wrap;
}

/* ── 認証ページ ──────────────────────────────────────────────────── */
.auth-page {
  align-items: center;
  background: var(--bg);
  display: flex;
  min-height: 100vh;
  justify-content: center;
  padding: 24px;
}
.auth-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: 420px;
  padding: 28px;
  width: 100%;
}
.auth-panel h1 { font-size: 26px; }

.btn-primary {
  background-color: var(--primary);
  border-color: var(--primary);
}

/* ── シンプルチャットページ ─────────────────────────────────────── */

/* body に chat-page-body クラスが付いたとき、全画面レイアウトに切り替え */
body.chat-page-body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
body.chat-page-body .navbar { flex-shrink: 0; }
body.chat-page-body main    { flex: 1; overflow: hidden; padding: 0 !important; }

.chat-page {
  display: flex;
  height: 100%;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.chat-header {
  align-items: center;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 14px 24px;
}
.chat-header h1 {
  font-size: 18px;
  line-height: 1.3;
  margin: 0;
}
.chat-header p {
  color: var(--muted);
  font-size: 13px;
  margin: 2px 0 0;
}
.chat-header-actions {
  align-items: center;
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}
.chat-header-actions .form-select {
  min-width: 180px;
}
.model-picker {
  align-items: center;
  display: flex;
  gap: 8px;
  margin: 0;
}
.model-picker span {
  color: var(--muted);
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

.chat-welcome {
  padding: 56px 0 24px;
  max-width: 680px;
  margin: 0 auto;
}
.chat-welcome h2 {
  font-size: 22px;
  margin: 0 0 18px;
  text-align: center;
}
.welcome-suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  text-align: left;
}
.suggestion-btn {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  line-height: 1.4;
  transition: border-color .15s, box-shadow .15s;
}
.suggestion-btn:hover {
  border-color: var(--primary);
  box-shadow: 0 1px 4px rgba(24,33,47,.08);
}

.message {
  display: flex;
  margin-bottom: 14px;
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}
.message-user      { flex-direction: row-reverse; }
.message-assistant { flex-direction: row; }

.msg-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.message-user .msg-body { align-items: flex-end; }

.message-text {
  border-radius: 8px;
  padding: 12px 14px;
}
.message-user .message-text {
  background: var(--primary);
  color: #fff;
  max-width: min(78%, 560px);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}
.message-assistant .message-text {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  line-height: 1.7;
  word-break: break-word;
  width: 100%;
}

/* タイピングインジケータ */
.typing-indicator {
  display: flex;
  gap: 5px;
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--muted);
  border-radius: 50%;
  animation: typing-bounce 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-7px); }
}

.chat-input-wrapper {
  flex-shrink: 0;
  padding: 12px 24px 18px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.chat-input-box {
  max-width: 760px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 10px 10px 10px 14px;
}
.chat-textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  font-size: 15px;
  line-height: 1.5;
  min-height: 26px;
  max-height: 200px;
  overflow-y: auto;
  background: transparent;
  color: var(--ink);
}
.chat-textarea::placeholder { color: var(--muted); }

.input-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.icon-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  transition: background .15s;
}
.icon-btn:hover { background: var(--bg); color: var(--ink); }

.send-btn {
  width: 34px;
  height: 34px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity .15s;
}
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.send-btn:not(:disabled):hover { opacity: .85; }

.img-remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #666;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* マークダウンコンテンツ */
.markdown-content { font-size: 15px; }
.markdown-content h1, .markdown-content h2, .markdown-content h3 {
  font-weight: 700;
  margin: 1.1em 0 .5em;
  line-height: 1.3;
}
.markdown-content h1 { font-size: 1.4em; }
.markdown-content h2 { font-size: 1.2em; }
.markdown-content h3 { font-size: 1.05em; }
.markdown-content p  { margin-bottom: .75em; line-height: 1.75; }
.markdown-content ul, .markdown-content ol { padding-left: 1.4em; margin-bottom: .75em; }
.markdown-content li { margin-bottom: .3em; }
.markdown-content strong { font-weight: 700; }
.markdown-content em     { font-style: italic; }
.markdown-content code {
  background: #f0f2f5;
  padding: 2px 5px;
  border-radius: 4px;
  font-size: .88em;
  font-family: 'Menlo', 'Monaco', 'Consolas', monospace;
}
.markdown-content pre {
  background: #f6f8fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: .75em 0;
}
.markdown-content pre code {
  background: none;
  padding: 0;
  font-size: .875em;
}
.markdown-content blockquote {
  border-left: 3px solid var(--line);
  padding-left: 12px;
  color: var(--muted);
  margin: .75em 0;
}
.markdown-content table { border-collapse: collapse; width: 100%; margin: .75em 0; }
.markdown-content th, .markdown-content td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  text-align: left;
}
.markdown-content th { background: var(--bg); font-weight: 600; }

/* コードコピーボタン */
.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  color: var(--muted);
  transition: background .15s;
}
.code-copy-btn:hover { background: var(--bg); }

/* ── レスポンシブ ────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .metric-grid  { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .welcome-suggestions { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .metric-grid  { grid-template-columns: 1fr; }
  .chat-header {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }
  .chat-header-actions {
    align-items: stretch;
    width: 100%;
  }
  .model-picker {
    flex: 1;
  }
  .chat-header-actions .form-select {
    min-width: 0;
  }
  .chat-header-actions form {
    flex-shrink: 0;
  }
  .chat-messages { padding: 16px 12px; }
  .chat-welcome { padding-top: 28px; }
  .message-user .message-text { max-width: 88%; }
  .chat-input-wrapper { padding: 8px 12px 12px; }
}
