@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;700&display=swap');

:root {
  --bg: #f3f0e8;
  --ink: #1c2a22;
  --muted: #5a6b60;
  --accent: #0d6e4f;
  --accent-light: #e6f4ef;
  --card: #fffcf6;
  --banner: #fff3cd;
  --banner-border: #e6c35c;
  --user: #0d6e4f;
  --user-text: #ffffff;
  --ai: #ffffff;
  --border: #d5ddd6;
  --shadow: 0 2px 8px rgba(13, 110, 79, 0.08);
  --font: 'Noto Sans JP', 'Segoe UI', 'Hiragino Sans', sans-serif;
  --radius: 14px;
}

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

body {
  font-family: var(--font);
  background:
    radial-gradient(ellipse at top left, #e8f2ec 0%, transparent 50%),
    radial-gradient(ellipse at bottom right, #e6f0f8 0%, transparent 50%),
    linear-gradient(180deg, #eef2ea 0%, var(--bg) 40%);
  color: var(--ink);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
}

/* ===== HEADER ===== */
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 252, 246, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 1.15rem;
  color: var(--ink);
}
.brand span {
  color: var(--accent);
  font-weight: 600;
  margin-left: 2px;
}
.nav-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.nav-right a {
  color: var(--muted);
  font-size: 0.875rem;
  text-decoration: none;
  transition: color 0.2s;
}
.nav-right a:hover { color: var(--accent); }

/* Badges */
.badge-free {
  background: #eef2ea;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.badge-paid {
  background: #e6f4ef;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  border: 1px solid var(--accent);
}

.btn-sub {
  background: #e67e22;
  color: #fff;
  border: none;
  padding: 0.35rem 0.8rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-sub:hover { background: #d35400; }

/* ===== BANNER ===== */
.banner {
  margin: 0;
  padding: 0.65rem 1.5rem;
  background: var(--banner);
  border-bottom: 1px solid var(--banner-border);
  color: #5c4810;
  font-size: 0.85rem;
  line-height: 1.5;
}

/* ===== LAYOUT ===== */
.chat-wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 100px);
}

/* ===== MODAL ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(3px);
}
.modal-content {
  background: #fff;
  border-radius: 16px;
  padding: 2rem;
  max-width: 480px;
  width: 90%;
  position: relative;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}
.modal-close {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  font-size: 1.5rem;
  color: var(--muted);
  cursor: pointer;
}
.modal-content h2 {
  color: var(--accent);
  font-size: 1.3rem;
  margin-bottom: 0.75rem;
}
.modal-content p {
  color: var(--ink);
  font-size: 0.92rem;
  margin-bottom: 1.25rem;
  line-height: 1.6;
}
.modal-actions {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
}
.btn-primary {
  background: #e67e22;
  color: #fff;
  font-size: 1rem;
  padding: 0.75rem 1.5rem;
  border-radius: 10px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn-primary:hover { background: #d35400; }

.modal-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}
.token-input-section .small-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.token-input-group {
  display: flex;
  gap: 0.5rem;
}
.token-input-group input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
}
.btn-secondary {
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary:hover {
  background: var(--accent);
  color: #fff;
}

/* ===== CONSENT ===== */
.consent {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.consent p { font-weight: 500; margin-bottom: 0.75rem; }
.consent label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.75rem 0;
  line-height: 1.6;
  font-size: 0.9rem;
  cursor: pointer;
}
.consent label input { margin-top: 3px; flex-shrink: 0; }
.consent a { color: var(--accent); }
.hidden { display: none !important; }

/* ===== MESSAGES ===== */
.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.5rem 0 1rem;
  scroll-behavior: smooth;
}
.msg {
  max-width: 90%;
  padding: 0.9rem 1.2rem;
  border-radius: var(--radius);
  line-height: 1.7;
  font-size: 0.95rem;
  position: relative;
  animation: fadeSlideIn 0.25s ease;
}
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg.user {
  align-self: flex-end;
  background: var(--user);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(13,110,79,0.2);
}
.msg.ai {
  align-self: flex-start;
  background: var(--ai);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}

/* AI Markdown スタイル */
.msg.ai h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  margin: 1rem 0 0.4rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--accent-light);
}
.msg.ai h3:first-child { margin-top: 0; }
.msg.ai p { margin: 0.4rem 0; }
.msg.ai ul, .msg.ai ol {
  margin: 0.4rem 0 0.4rem 1.4rem;
}
.msg.ai li { margin: 0.2rem 0; }
.msg.ai strong { color: var(--ink); }
.msg.ai em { color: var(--muted); }
.msg.ai code {
  background: #f0f4f0;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15em 0.4em;
  font-size: 0.85em;
  font-family: 'Consolas', 'Courier New', monospace;
}
.msg.ai pre {
  background: #f0f4f0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  overflow-x: auto;
  margin: 0.6rem 0;
}
.msg.ai pre code {
  background: none;
  border: none;
  padding: 0;
}
.msg.ai table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6rem 0;
  font-size: 0.88rem;
}
.msg.ai th, .msg.ai td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.7rem;
  text-align: left;
}
.msg.ai th {
  background: var(--accent-light);
  font-weight: 600;
  color: var(--accent);
}
.msg.ai tr:nth-child(even) td { background: #fafaf8; }
.msg.ai blockquote {
  border-left: 3px solid var(--accent);
  margin: 0.5rem 0;
  padding: 0.4rem 0.75rem;
  color: var(--muted);
  font-style: italic;
}

/* コピーボタン */
.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: var(--accent-light);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  color: var(--accent);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
  font-family: var(--font);
}
.msg.ai:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: var(--accent); color: #fff; }
.copy-btn.copied {
  background: var(--accent);
  color: #fff;
  opacity: 1;
}

/* ソース参照 */
.sources {
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}
.sources-label { font-weight: 500; }
.source-tag {
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-size: 0.75rem;
}

/* ストリーミング中のインジケータ */
.streaming-indicator {
  display: inline-block;
  width: 6px;
  height: 14px;
  background: var(--accent);
  border-radius: 2px;
  margin-left: 2px;
  animation: blink 0.7s infinite;
  vertical-align: middle;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

/* ===== INPUT ===== */
.input-row {
  display: flex;
  gap: 0.6rem;
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
  background: transparent;
}
.input-row textarea {
  flex: 1;
  resize: vertical;
  min-height: 54px;
  max-height: 180px;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  font: inherit;
  font-size: 0.95rem;
  background: var(--card);
  transition: border-color 0.2s, box-shadow 0.2s;
  color: var(--ink);
}
.input-row textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13,110,79,0.12);
}
.input-row textarea:disabled { opacity: 0.5; cursor: not-allowed; }
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 0 1.25rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.95rem;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 2px 6px rgba(13,110,79,0.2);
}
.btn:hover:not(:disabled) {
  background: #0a5c40;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(13,110,79,0.3);
}
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

/* ===== DOCS ===== */
.doc {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  line-height: 1.8;
}
.doc h1 { font-size: 1.8rem; color: var(--accent); margin-bottom: 0.5rem; }
.doc h2 { font-size: 1.1rem; margin-top: 2rem; margin-bottom: 0.5rem; color: var(--ink); }
.doc p { margin: 0.6rem 0; color: var(--ink); }
.muted { color: var(--muted); font-size: 0.875rem; }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .chat-wrap { padding: 0.75rem 0.75rem 1.5rem; }
  .msg { max-width: 97%; font-size: 0.92rem; }
  .top { padding: 0.7rem 1rem; }
  .brand { font-size: 1rem; }
}
