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

body {
  font-family: "Helvetica Neue", Arial, "Hiragino Sans", "Meiryo", sans-serif;
  background: #eef1f6;
  color: #222;
  line-height: 1.65;
}

/* ===== レイアウト ===== */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}

/* ===== ヘッダー ===== */
header {
  border-top: 4px solid #1a4f8b;
  background: #fff;
  border-radius: 12px;
  padding: 20px 24px 16px;
  margin-bottom: 20px;
  box-shadow: 0 2px 12px rgba(26, 79, 139, 0.08);
}

header h1 {
  font-size: 1.45rem;
  font-weight: 700;
  color: #1a4f8b;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 8px;
}

header h1::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  background: linear-gradient(135deg, #1a4f8b, #3b82c4);
  border-radius: 50%;
}

.note {
  font-size: 0.83rem;
  color: #778;
  margin-top: 6px;
  line-height: 1.6;
}

/* ヘッダー内：タイトルとクリアボタンを横並びに */
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.clear-btn {
  padding: 6px 14px;
  background: #fff;
  color: #1a4f8b;
  border: 1.5px solid #d0d8e4;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.clear-btn:hover {
  background: #f0f4fa;
  border-color: #1a4f8b;
}

/* ===== よく使う質問ショートカット ===== */
.quick-questions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.qq-label {
  font-size: 0.8rem;
  color: #778;
  margin-right: 2px;
}

.qq-btn {
  padding: 6px 12px;
  background: #fff;
  color: #1a4f8b;
  border: 1.5px solid #cddaea;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
}

.qq-btn:hover {
  background: #e8f0fb;
  transform: translateY(-1px);
}

/* ===== チャットウィンドウ ===== */
.chat-window {
  background: #f8fafc;
  border: 1px solid #e0e6ed;
  border-radius: 14px;
  height: 440px;
  overflow-y: auto;
  padding: 20px 16px;
  margin-bottom: 14px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.04);
  scroll-behavior: smooth;
}

/* スクロールバー（Webkit系） */
.chat-window::-webkit-scrollbar {
  width: 5px;
}
.chat-window::-webkit-scrollbar-track {
  background: transparent;
}
.chat-window::-webkit-scrollbar-thumb {
  background: #c9d4e0;
  border-radius: 10px;
}

/* ===== メッセージ吹き出し ===== */
.msg {
  margin-bottom: 16px;
  padding: 11px 15px;
  border-radius: 12px;
  max-width: 82%;
  white-space: pre-wrap;
  font-size: 0.93rem;
  line-height: 1.7;
  animation: fadeUp 0.2s ease-out;
}

.msg.no-anim {
  animation: none;
}

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

.msg.user {
  background: linear-gradient(135deg, #1a4f8b 0%, #2563a8 100%);
  color: #fff;
  margin-left: auto;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(26, 79, 139, 0.22);
}

.msg.bot {
  background: #fff;
  color: #222;
  border-left: 3px solid #3b82c4;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.07);
}

.msg-text {
  white-space: pre-wrap;
}

.msg-time {
  display: block;
  margin-top: 6px;
  font-size: 0.68rem;
  opacity: 0.6;
}

.msg .source {
  display: block;
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid #e0eaf4;
  font-size: 0.73rem;
  color: #2a7d5a;
  font-style: italic;
}

/* ボットメッセージ下部のツールバー（コピー・評価・再送信） */
.msg-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.copy-btn,
.retry-btn {
  padding: 4px 10px;
  background: #f0f4fa;
  color: #1a4f8b;
  border: 1px solid #d0d8e4;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  transition: background 0.15s;
}

.copy-btn:hover,
.retry-btn:hover {
  background: #e0eaf6;
}

.fb-btn {
  padding: 3px 8px;
  background: #fff;
  border: 1px solid #e0e6ed;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s, transform 0.1s;
}

.fb-btn:hover:not(:disabled) {
  background: #f0f4fa;
  transform: translateY(-1px);
}

.fb-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.fb-thanks {
  font-size: 0.72rem;
  color: #2a7d5a;
}

.loading-bubble {
  color: #8899aa;
  font-style: italic;
}

/* ===== 入力エリア ===== */
.input-area {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.input-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.input-area textarea {
  flex: 1;
  padding: 11px 14px;
  border: 1.5px solid #d0d8e4;
  border-radius: 10px;
  resize: vertical;
  font-size: 0.93rem;
  font-family: inherit;
  color: #222;
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
  line-height: 1.55;
}

.input-area textarea:focus {
  outline: none;
  border-color: #1a4f8b;
  box-shadow: 0 0 0 3px rgba(26, 79, 139, 0.1);
}

.input-area textarea::placeholder {
  color: #aab;
  font-size: 0.88rem;
}

.input-meta {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

#char-count {
  font-size: 0.72rem;
  color: #99a;
}

#char-count.over {
  color: #c0392b;
  font-weight: 700;
}

.input-area button {
  padding: 0 22px;
  height: 44px;
  background: linear-gradient(135deg, #1a4f8b 0%, #2563a8 100%);
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.93rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: opacity 0.18s, transform 0.12s, box-shadow 0.18s;
  box-shadow: 0 2px 8px rgba(26, 79, 139, 0.22);
  white-space: nowrap;
}

.input-area button:hover:not(:disabled) {
  opacity: 0.88;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(26, 79, 139, 0.28);
}

.input-area button:active:not(:disabled) {
  transform: translateY(0);
}

.input-area button:disabled {
  background: #b0bcc8;
  cursor: not-allowed;
  box-shadow: none;
}

/* ===== 注意文 ===== */
.warning {
  margin-top: 10px;
  font-size: 0.75rem;
  color: #b33;
  display: flex;
  align-items: flex-start;
  gap: 4px;
}

.warning::before {
  content: "⚠";
  flex-shrink: 0;
  font-size: 0.8rem;
}

/* ===== 管理者ページ ===== */
.admin header {
  border-top-color: #2a5fa3;
}

.admin header h1::before {
  background: linear-gradient(135deg, #2a5fa3, #4a90d9);
}

.admin .card {
  background: #fff;
  border: 1px solid #e0e6ed;
  border-radius: 14px;
  padding: 22px 24px;
  margin-bottom: 22px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

.admin .card h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #1a4f8b;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1.5px solid #e8eef6;
  letter-spacing: 0.02em;
}

.admin textarea,
.admin input[type="password"],
.admin input[type="text"],
.admin select {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid #d0d8e4;
  border-radius: 10px;
  font-size: 0.93rem;
  font-family: inherit;
  margin-bottom: 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #fafbfd;
  color: #222;
}

.admin textarea:focus,
.admin input[type="password"]:focus,
.admin input[type="text"]:focus,
.admin select:focus {
  outline: none;
  border-color: #1a4f8b;
  box-shadow: 0 0 0 3px rgba(26, 79, 139, 0.1);
}

.admin button {
  padding: 9px 18px;
  background: linear-gradient(135deg, #1a4f8b 0%, #2563a8 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  margin-right: 8px;
  letter-spacing: 0.03em;
  transition: opacity 0.18s, transform 0.12s, box-shadow 0.18s;
  box-shadow: 0 2px 6px rgba(26, 79, 139, 0.18);
}

.admin button:hover {
  opacity: 0.88;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(26, 79, 139, 0.24);
}

.admin button.danger {
  background: linear-gradient(135deg, #c0392b 0%, #d9534f 100%);
  box-shadow: 0 2px 6px rgba(192, 57, 43, 0.2);
}

.admin button.danger:hover {
  box-shadow: 0 4px 12px rgba(192, 57, 43, 0.28);
}

.admin button.ok {
  background: linear-gradient(135deg, #2a7d5a 0%, #38a06c 100%);
  box-shadow: 0 2px 6px rgba(42, 125, 90, 0.2);
}

.admin button.ok:hover {
  box-shadow: 0 4px 12px rgba(42, 125, 90, 0.28);
}

.admin button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.info-msg {
  font-size: 0.84rem;
  color: #2a7d5a;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 1.2em;
}

.info-msg:not(:empty)::before {
  content: "✓";
  font-size: 0.85rem;
}

/* ===== ローディング表示 ===== */
.loading {
  font-size: 0.85rem;
  color: #8899aa;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
}

.loading::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #c9d4e0;
  border-top-color: #1a4f8b;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

/* ===== リスト ===== */
.list {
  margin-top: 14px;
}

.list-item {
  border: 1px solid #e6ecf4;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: #f8fafc;
  transition: box-shadow 0.15s;
  animation: fadeUp 0.18s ease-out;
}

.list-item:hover {
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
}

.list-item .q {
  font-weight: 700;
  color: #1a4f8b;
  font-size: 0.93rem;
  margin-bottom: 4px;
}

.list-item .a {
  margin: 8px 0 4px;
  white-space: pre-wrap;
  font-size: 0.9rem;
  color: #333;
  line-height: 1.65;
}

.list-item .meta {
  font-size: 0.73rem;
  color: #99a;
  margin-top: 6px;
}

.list-item textarea {
  margin-top: 10px;
  border-radius: 8px;
  border: 1.5px solid #d0d8e4;
  background: #fff;
  width: 100%;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  color: #222;
  resize: vertical;
  transition: border-color 0.2s, box-shadow 0.2s;
  margin-bottom: 10px;
}

.list-item textarea:focus {
  outline: none;
  border-color: #1a4f8b;
  box-shadow: 0 0 0 3px rgba(26, 79, 139, 0.1);
}

.list-item .btn-row {
  display: flex;
  gap: 8px;
}

/* ===== ログインセクション ===== */
#login-section {
  max-width: 400px;
}

#login-msg {
  font-size: 0.83rem;
  margin-top: 6px;
  min-height: 1.2em;
}

#login-msg.warning::before {
  content: none;
}

/* ===== 管理画面：統計ダッシュボード ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.stat-card {
  background: #f8fafc;
  border: 1px solid #e6ecf4;
  border-radius: 10px;
  padding: 14px 16px;
  text-align: center;
}

.stat-card-wide {
  grid-column: 1 / -1;
  text-align: left;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: #1a4f8b;
}

.stat-label {
  font-size: 0.75rem;
  color: #778;
  margin-top: 4px;
}

.stat-sub {
  font-size: 0.8rem;
  color: #333;
  margin-top: 6px;
  line-height: 1.6;
}

/* ===== 管理画面：タブ ===== */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 9px 16px;
  background: #fff;
  color: #1a4f8b;
  border: 1.5px solid #d0d8e4;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  transition: background 0.15s;
}

.tab-btn:hover {
  background: #f0f4fa;
}

.tab-btn.active {
  background: linear-gradient(135deg, #1a4f8b 0%, #2563a8 100%);
  color: #fff;
  border-color: #1a4f8b;
}

/* ===== 管理画面：検索・絞り込みバー ===== */
.toolbar-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.toolbar-row .search-bar {
  flex: 1;
  min-width: 160px;
  margin-bottom: 0;
}

.toolbar-row .filter-select {
  width: auto;
  min-width: 150px;
  margin-bottom: 0;
}

.toolbar-row button {
  margin-bottom: 0;
}

/* ===== タイピング風ローディング ===== */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.typing span {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #9aa8ba;
  border-radius: 50%;
  animation: typingBounce 1.2s infinite ease-in-out;
}

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

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

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}
