/* AI Poetry Assistant - 詩生成アプリケーションのスタイル */

/* フォント設定 */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* カスタムプライマリカラー */
:root {
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;
  --primary-200: #bfdbfe;
  --primary-300: #93c5fd;
  --primary-400: #60a5fa;
  --primary-500: #3b82f6;
  --primary-600: #2563eb;
  --primary-700: #1d4ed8;
  --primary-800: #1e40af;
  --primary-900: #1e3a8a;
}

/* 認証フォームのスタイル */
.auth-tab.active {
  background-color: var(--primary-600);
  color: white;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

.auth-tab:not(.active):hover {
  background-color: var(--primary-50);
  color: var(--primary-700);
}

/* サイドバーナビゲーション */
.sidebar-nav.active {
  background-color: var(--primary-50);
  color: var(--primary-700);
  border-left: 3px solid var(--primary-600);
}

.sidebar-nav:not(.active):hover {
  background-color: #f9fafb;
}

/* カレンダー風のスタイル */
.calendar-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 0.375rem;
  transition: all 0.2s ease;
}

.calendar-day:hover {
  background-color: var(--primary-50);
}

.calendar-day.has-poem {
  background-color: var(--primary-100);
  border: 2px solid var(--primary-300);
}

.calendar-day.selected {
  background-color: var(--primary-600);
  color: white;
}

/* 詩の表示スタイル */
.poem-content {
  background: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%);
  border-left: 4px solid var(--primary-500);
  font-family: 'Georgia', 'Times New Roman', serif;
  line-height: 1.8;
  padding: 1.5rem;
  border-radius: 0.5rem;
}

.poem-title {
  color: var(--primary-700);
  font-weight: 600;
  margin-bottom: 1rem;
}

/* メッセージバブル */
.message.user .message-bubble {
  background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-700) 100%);
  color: white;
}

.message.assistant .message-bubble {
  background: white;
  border: 1px solid #e5e7eb;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* アニメーション */
.fade-in {
  animation: fadeIn 0.3s ease-in-out;
}

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

.slide-in {
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from { transform: translateX(-20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ローディング状態 */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  border: 2px solid var(--primary-600);
  border-top: 2px solid transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  transform: translate(-50%, -50%);
}

@keyframes spin {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ユーティリティクラス */
.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.truncate-2-lines {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* スクロールバーのカスタマイズ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* Firefox用のスクロールバー */
* {
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
}

/* メッセージエリアのスムーズスクロール */
#messages-container {
  scroll-behavior: smooth;
}

/* テキストエリアの自動リサイズ */
#message-input {
  min-height: 48px;
  max-height: 120px;
  overflow-y: hidden;
  resize: none;
}

/* ボタンのホバーエフェクト */
button {
  transition: all 0.2s ease-in-out;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

/* セレクトボックスのカスタマイズ */
select {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
}

/* ローディングアニメーション */
.loading-dots {
  display: inline-flex;
  align-items: center;
}

.loading-dots::after {
  content: '';
  animation: dots 1.5s infinite;
}

@keyframes dots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}

/* モバイル用ハンバーガーメニュー */
.mobile-menu-toggle {
  display: none;
}

.mobile-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 40;
}

.mobile-overlay.active {
  display: block;
}

.sidebar-mobile {
  transform: translateX(-100%);
  transition: transform 0.3s ease-in-out;
}

.sidebar-mobile.active {
  transform: translateX(0);
}

/* タブレット対応 (769px - 1024px) */
@media (max-width: 1024px) {
  /* サイドバーの幅を調整 */
  .w-64 {
    width: 16rem; /* 256px から 256px に維持 */
  }
  
  .w-80 {
    width: 18rem; /* 320px から 288px に縮小 */
  }
}

/* タブレット対応 (769px - 768px) */
@media (max-width: 768px) {
  /* ハンバーガーメニューを表示 */
  .mobile-menu-toggle {
    display: block;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 60;
    background-color: var(--primary-600);
    color: white;
    border: none;
    border-radius: 0.5rem;
    padding: 0.75rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  }

  /* サイドバーをモバイル用に調整 */
  .sidebar-main {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    z-index: 50;
    background-color: white;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  }

  /* メインコンテンツの調整 */
  .main-app-container {
    margin-left: 0 !important;
  }

  .main-content-area {
    width: 100% !important;
  }

  /* チャットエリアのサイドバーを非表示 */
  .chat-sidebar {
    display: none;
  }

  .chat-main {
    width: 100% !important;
  }

  /* 詩生成エリアのサイドバーを最小化 */
  .poetry-sidebar {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background-color: white;
    z-index: 30;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
  }

  .poetry-sidebar.active {
    transform: translateY(0);
  }

  /* RAGエリアのサイドバーも同様 */
  .rag-sidebar {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background-color: white;
    z-index: 30;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
  }

  .rag-sidebar.active {
    transform: translateY(0);
  }

  /* 入力フォームの調整 */
  .message-input-container {
    padding: 1rem;
  }

  /* グリッドレイアウトの調整 */
  .grid.md\:grid-cols-2,
  .grid.lg\:grid-cols-3 {
    grid-template-columns: 1fr !important;
  }
}

/* スマートフォン対応 (480px以下) */
@media (max-width: 640px) {
  /* 基本的なフォントサイズ調整 */
  .text-3xl {
    font-size: 1.5rem !important;
  }

  .text-2xl {
    font-size: 1.25rem !important;
  }

  .text-xl {
    font-size: 1.125rem !important;
  }

  .text-lg {
    font-size: 1rem !important;
  }

  /* パディングの調整 */
  .p-6 {
    padding: 1rem !important;
  }

  .p-4 {
    padding: 0.75rem !important;
  }

  .px-4 {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  .py-4 {
    padding-top: 0.75rem !important;
    padding-bottom: 0.75rem !important;
  }

  /* サイドバーの幅調整 */
  .sidebar-main {
    width: 260px;
  }

  /* ハンバーガーメニューボタンの調整 */
  .mobile-menu-toggle {
    top: 0.75rem;
    left: 0.75rem;
    padding: 0.5rem;
  }

  /* 認証画面の調整 */
  .auth-container {
    padding: 1rem;
  }

  .auth-card {
    padding: 1.5rem !important;
  }

  /* フォーム要素の調整 */
  input, select, textarea {
    font-size: 16px !important; /* iOS Safariでのズームを防ぐ */
    padding: 0.75rem !important;
  }

  /* ボタンの調整 */
  button {
    padding: 0.75rem 1rem !important;
    font-size: 0.875rem !important;
    min-height: 44px; /* タッチターゲットの最小サイズ */
  }

  /* メッセージバブルの調整 */
  .message-bubble {
    max-width: 85% !important;
    padding: 0.75rem !important;
    font-size: 0.875rem !important;
  }

  /* 詩生成エリアの調整 */
  .poem-input-area {
    padding: 1rem !important;
  }
}

/* カスタムセレクトボックスのスタイル */
select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: none;
}

/* セレクトボックスの矢印アイコンを隠す（全ブラウザ対応） */
select::-ms-expand {
  display: none;
}

/* カスタムドロップダウンのホバー効果 */
.relative:hover .fa-chevron-down {
  color: #6b7280 !important;
}

/* フォーカス時のスタイル */
select:focus + div .fa-chevron-down {
  color: #2563eb !important;
}

  .poem-prompt-textarea {
    min-height: 120px !important;
  }

  /* データ管理エリアの調整 */
  .rag-data-grid {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }

  /* ナビゲーションボタンの調整 */
  .sidebar-nav {
    padding: 0.75rem !important;
    font-size: 0.875rem !important;
  }

  /* スクロール領域の調整 */
  .overflow-y-auto {
    -webkit-overflow-scrolling: touch;
  }

  /* チャットメッセージエリアの調整 */
  .chat-messages {
    padding: 0.75rem !important;
    gap: 0.75rem !important;
  }

  /* ファイルアップロードエリアの調整 */
  .file-upload-area {
    padding: 1.5rem 1rem !important;
    font-size: 0.875rem !important;
  }
}

/* 極小スマートフォン対応 (360px以下) */
@media (max-width: 360px) {
  /* さらに小さい画面での調整 */
  .auth-card {
    padding: 1rem !important;
    margin: 0.5rem !important;
  }

  .sidebar-main {
    width: 240px;
  }

  .mobile-menu-toggle {
    top: 0.5rem;
    left: 0.5rem;
    padding: 0.375rem;
  }

  /* フォントサイズをさらに調整 */
  .text-2xl {
    font-size: 1.125rem !important;
  }

  .text-xl {
    font-size: 1rem !important;
  }

  /* ボタンサイズ調整 */
  button {
    padding: 0.5rem 0.75rem !important;
    font-size: 0.8125rem !important;
  }

  /* 入力要素の調整 */
  input, select, textarea {
    padding: 0.625rem !important;
  }
}

/* ランドスケープモードの調整 */
@media (max-width: 768px) and (orientation: landscape) {
  /* 横向きの場合の特別な調整 */
  .mobile-menu-toggle {
    top: 0.5rem;
    left: 0.5rem;
  }

  /* サイドバーの高さ調整 */
  .sidebar-main {
    height: 100vh;
  }

  /* チャットエリアの高さ調整 */
  .chat-container {
    height: 100vh;
  }
}

/* タッチデバイス用の調整 */
@media (hover: none) and (pointer: coarse) {
  /* ホバーエフェクトを無効化 */
  button:hover {
    transform: none;
  }

  /* タップ時の視覚フィードバック */
  button:active {
    transform: scale(0.98);
    background-color: var(--primary-700);
  }

  /* タッチフレンドリーなサイズ */
  .touch-target {
    min-height: 44px;
    min-width: 44px;
  }

  /* スクロールの調整 */
  .overflow-auto {
    -webkit-overflow-scrolling: touch;
  }
}

/* フォーカス状態の改善 */
*:focus {
  outline: none;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* カスタムスクロール */
.custom-scroll {
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
}

.custom-scroll::-webkit-scrollbar {
  width: 6px;
}

.custom-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.custom-scroll::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

.custom-scroll::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}