/* ==========================================================
   emo1 - AI Chat Application Stylesheet
   スマホファースト / 白基調 / ネイビーアクセント
   ========================================================== */

/* ----------------------------------------------------------
   カラーパレット・基本変数
   ---------------------------------------------------------- */
:root {
  --color-bg: #ffffff;
  --color-surface: #f8fafc;
  --color-border: #e2e8f0;
  --color-text-primary: #1e293b;
  --color-text-secondary: #64748b;
  --color-accent: #3b82f6;
  --color-accent-hover: #2563eb;
  --color-accent-light: #eff6ff;
  --color-user-bubble: #1e293b;
  --color-user-text: #ffffff;
  --color-ai-bubble: #f1f5f9;
  --color-ai-text: #1e293b;
  --color-error: #dc2626;
  --color-success: #16a34a;

  --font-family: system-ui, -apple-system, 'Hiragino Sans', sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;
  --header-height: 56px;
}

/* ----------------------------------------------------------
   リセット・ベーススタイル
   ---------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.6;
  color: var(--color-text-primary);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* テキスト選択色 */
::selection {
  background-color: var(--color-accent);
  color: var(--color-user-text);
}

/* スクロールバー（webkit） */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background-color: var(--color-border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-text-secondary);
}

/* ----------------------------------------------------------
   ヘッダー
   ---------------------------------------------------------- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background-color: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  max-width: 768px;
  margin: 0 auto;
  padding: 0 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  display: block;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: -0.02em;
}

/* 歯車アイコン（CSSのみ） */
.header-settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  transition: background-color 0.15s;
}

.header-settings-btn:hover {
  background-color: var(--color-surface);
}

.gear-icon {
  display: block;
  width: 20px;
  height: 20px;
  position: relative;
}

/* 歯車の中心円 */
.gear-icon::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  border: 2px solid var(--color-text-secondary);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

/* 歯車の外周（歯は枠線のみで表現） */
.gear-icon::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  border: 2px solid var(--color-text-secondary);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  /* 歯車の歯をdash配列で表現 */
  border-style: dashed;
}

/* ----------------------------------------------------------
   チャットコンテナ
   ---------------------------------------------------------- */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scroll-behavior: smooth;
}

/* ----------------------------------------------------------
   ウェルカム画面
   ---------------------------------------------------------- */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--header-height) - 120px);
  padding: 24px 16px;
  text-align: center;
}

.welcome.hidden {
  display: none;
}

.welcome-logo {
  margin-bottom: 16px;
  opacity: 0.9;
}

.welcome-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.welcome-subtitle {
  font-size: 15px;
  color: var(--color-text-secondary);
  margin-bottom: 32px;
}

.welcome-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 360px;
}

.welcome-card {
  display: block;
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-bg);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-family);
  font-size: 14px;
  color: var(--color-text-primary);
  transition: border-color 0.15s, background-color 0.15s;
}

.welcome-card:hover {
  border-color: var(--color-accent);
  background-color: var(--color-accent-light);
}

.welcome-card-text {
  line-height: 1.5;
}

/* ----------------------------------------------------------
   チャットメッセージ
   ---------------------------------------------------------- */
.messages-area {
  max-width: 768px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-wrapper {
  display: flex;
  width: 100%;
  animation: messageIn 0.2s ease-out;
}

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

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

.message-bubble {
  max-width: 85%;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.65;
  word-break: break-word;
  overflow-wrap: break-word;
}

/* ユーザーバブル */
.message-wrapper.user .message-bubble {
  background-color: var(--color-user-bubble);
  color: var(--color-user-text);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
}

/* AIバブル */
.message-wrapper.assistant .message-bubble {
  background-color: var(--color-ai-bubble);
  color: var(--color-ai-text);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
}

/* メッセージ出現アニメーション */
@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ----------------------------------------------------------
   タイピングインジケーター
   ---------------------------------------------------------- */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--color-text-secondary);
  animation: typingDot 1.2s ease-in-out infinite;
}

.typing-indicator .dot:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-indicator .dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typingDot {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* ----------------------------------------------------------
   マークダウンレンダリング（AIバブル内）
   ---------------------------------------------------------- */
.message-bubble p {
  margin-bottom: 8px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble strong {
  font-weight: 600;
}

.message-bubble em {
  font-style: italic;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
  font-weight: 700;
  margin-top: 16px;
  margin-bottom: 8px;
  line-height: 1.3;
}

.message-bubble h1 { font-size: 20px; }
.message-bubble h2 { font-size: 18px; }
.message-bubble h3 { font-size: 16px; }

.message-bubble h1:first-child,
.message-bubble h2:first-child,
.message-bubble h3:first-child {
  margin-top: 0;
}

.message-bubble ul,
.message-bubble ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-bubble li {
  margin-bottom: 4px;
}

.message-bubble blockquote {
  margin: 8px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--color-border);
  color: var(--color-text-secondary);
}

.message-bubble a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-bubble a:hover {
  color: var(--color-accent-hover);
}

/* インラインコード */
.message-bubble code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background-color: rgba(0, 0, 0, 0.06);
}

/* ユーザーバブル内のインラインコード */
.message-wrapper.user .message-bubble code {
  background-color: rgba(255, 255, 255, 0.15);
}

/* コードブロック */
.code-block-wrapper {
  position: relative;
  margin: 10px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  background-color: #1e293b;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background-color: rgba(255, 255, 255, 0.06);
  font-size: 12px;
  color: #94a3b8;
}

.code-block-lang {
  text-transform: lowercase;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background-color: rgba(255, 255, 255, 0.08);
  color: #94a3b8;
  font-family: var(--font-family);
  font-size: 12px;
  cursor: pointer;
  transition: background-color 0.15s;
}

.copy-btn:hover {
  background-color: rgba(255, 255, 255, 0.15);
}

.copy-btn.copied {
  color: var(--color-success);
}

.code-block-wrapper pre {
  margin: 0;
  padding: 12px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.code-block-wrapper code {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  color: #e2e8f0;
  background: none;
  padding: 0;
  border-radius: 0;
  white-space: pre;
}

/* テーブル */
.message-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 14px;
}

.message-bubble th,
.message-bubble td {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  text-align: left;
}

.message-bubble th {
  background-color: var(--color-surface);
  font-weight: 600;
}

/* ----------------------------------------------------------
   入力エリア
   ---------------------------------------------------------- */
.input-area {
  position: sticky;
  bottom: 0;
  background-color: var(--color-bg);
  border-top: 1px solid var(--color-border);
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.input-area-inner {
  max-width: 768px;
  margin: 0 auto;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface);
  transition: border-color 0.15s;
}

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

.message-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text-primary);
  resize: none;
  overflow-y: hidden;
  max-height: calc(1.5em * 4 + 4px);
}

.message-input::placeholder {
  color: var(--color-text-secondary);
}

/* 送信ボタン */
.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background-color: var(--color-border);
  color: var(--color-text-secondary);
  cursor: not-allowed;
  transition: background-color 0.15s, color 0.15s, transform 0.1s;
}

.send-btn.active {
  background-color: var(--color-accent);
  color: #ffffff;
  cursor: pointer;
}

.send-btn.active:hover {
  background-color: var(--color-accent-hover);
}

.send-btn.active:active {
  transform: scale(0.94);
}

.input-hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--color-text-secondary);
  text-align: right;
  opacity: 0.7;
}

/* ----------------------------------------------------------
   モーダル
   ---------------------------------------------------------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background-color: rgba(0, 0, 0, 0.4);
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  width: 100%;
  max-width: 440px;
  background-color: var(--color-bg);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

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

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text-primary);
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 22px;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background-color 0.15s;
}

.modal-close:hover {
  background-color: var(--color-surface);
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* フォーム要素 */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
}

.form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: var(--color-surface);
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text-primary);
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}

.form-textarea:focus {
  border-color: var(--color-accent);
}

.form-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: var(--color-surface);
  font-family: var(--font-family);
  font-size: 14px;
  color: var(--color-text-primary);
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  transition: border-color 0.15s;
}

.form-select:focus {
  border-color: var(--color-accent);
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 1px solid var(--color-error);
  border-radius: var(--radius-sm);
  background-color: transparent;
  font-family: var(--font-family);
  font-size: 14px;
  font-weight: 600;
  color: var(--color-error);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.btn-danger:hover {
  background-color: var(--color-error);
  color: #ffffff;
}

/* ----------------------------------------------------------
   エラーメッセージ
   ---------------------------------------------------------- */
.error-message {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background-color: #fef2f2;
  color: var(--color-error);
  font-size: 14px;
  border: 1px solid #fecaca;
}

/* ----------------------------------------------------------
   レスポンシブ
   ---------------------------------------------------------- */

/* タブレット以上 */
@media (min-width: 768px) {
  .message-bubble {
    max-width: 65%;
  }

  .welcome-cards {
    max-width: 420px;
  }
}

/* デスクトップ */
@media (min-width: 1024px) {
  .chat-container {
    padding: 24px;
  }

  .input-area {
    padding: 16px 24px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* コンパクト画面 */
@media (max-width: 374px) {
  .welcome-title {
    font-size: 24px;
  }

  .welcome-subtitle {
    font-size: 14px;
  }

  .welcome-card {
    padding: 12px 14px;
    font-size: 13px;
  }

  .message-bubble {
    padding: 8px 12px;
    font-size: 14px;
  }
}

/* ----------------------------------------------------------
   印刷時
   ---------------------------------------------------------- */
/* ----------------------------------------------------------
   利用確認画面（コンセント）
   ---------------------------------------------------------- */
.consent-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background-color: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.consent-overlay.hidden {
  display: none;
}

.consent-card {
  width: 100%;
  max-width: 560px;
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 32px 24px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}

.consent-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--color-text-primary);
  margin-top: 16px;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}

.consent-subtitle {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-bottom: 24px;
}

.consent-items {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 28px;
}

.consent-item {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  background-color: var(--color-bg);
}

.consent-item-caution {
  border-color: #e8c9a0;
  background-color: #fffbf5;
}

.consent-item-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: 6px;
}

.consent-item-text {
  font-size: 13px;
  line-height: 1.65;
  color: var(--color-text-secondary);
}

.consent-btn {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-md);
  background-color: var(--color-accent);
  color: #fff;
  font-family: var(--font-family);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s;
}

.consent-btn:hover {
  background-color: var(--color-accent-hover);
}

.consent-footer-link {
  text-align: center;
  margin-top: 14px;
}

.consent-link {
  border: none;
  background: none;
  color: var(--color-text-secondary);
  font-family: var(--font-family);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.consent-link:hover {
  color: var(--color-accent);
}

/* ----------------------------------------------------------
   プライバシーポリシーモーダル
   ---------------------------------------------------------- */
.privacy-modal {
  max-width: 600px;
  max-height: 85dvh;
  overflow-y: auto;
}

.privacy-body {
  font-size: 13px;
  line-height: 1.7;
  color: var(--color-text-primary);
}

.privacy-meta {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-border);
}

.privacy-body h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text-primary);
  margin-top: 20px;
  margin-bottom: 6px;
}

.privacy-body h3:first-of-type {
  margin-top: 0;
}

.privacy-body p {
  margin-bottom: 8px;
}

.privacy-body ul {
  padding-left: 18px;
  margin-bottom: 8px;
}

.privacy-body li {
  margin-bottom: 4px;
}

.privacy-body a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ----------------------------------------------------------
   印刷時
   ---------------------------------------------------------- */
@media print {
  .input-area,
  .header-settings-btn,
  .consent-overlay {
    display: none;
  }

  .header {
    position: static;
    border-bottom: 1px solid #000;
  }

  .chat-container {
    overflow: visible;
  }
}
