/* =============================================================
   栄養先生ひろし - スタイルシート
   Gemini風UI / 緑〜エメラルドテーマ
   ============================================================= */

/* ===== リセット ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* カラーパレット（緑〜エメラルド系） */
  --color-primary: #10b981;
  --color-primary-dark: #059669;
  --color-primary-light: #d1fae5;
  --color-accent: #34d399;

  /* 背景 */
  --color-bg-top: #ffffff;
  --color-bg-bottom: #ecfdf5;
  --color-surface: #ffffff;

  /* テキスト */
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-text-light: #9ca3af;

  /* UI */
  --color-border: #e5e7eb;
  --color-bubble-user: #f3f4f6;
  --color-bubble-user-text: #1f2937;
  --color-error: #dc2626;
  --color-error-bg: #fee2e2;

  /* シャドウ */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 40px rgba(16, 185, 129, 0.12);

  /* レイアウト */
  --radius-pill: 28px;
  --radius-card: 20px;
  --radius-bubble: 18px;
  --header-height: 56px;
}

/* hidden 属性を CSS の display ルールより優先させる */
[hidden] { display: none !important; }

/* ===== ベース ===== */
html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic",
    "Noto Sans JP", "Meiryo", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background: linear-gradient(180deg, var(--color-bg-top) 0%, var(--color-bg-bottom) 100%);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

input, textarea {
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
  outline: none;
}

.screen {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* =============================================================
   ログイン画面
   ============================================================= */
#login-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-lg);
  padding: 40px 28px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.login-logo {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--color-primary-light);
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.2);
}

.login-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: 0.02em;
}

.login-desc {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  text-align: center;
  line-height: 1.6;
}

#login-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

#login-form input {
  width: 100%;
  padding: 14px 18px;
  border: 1.5px solid var(--color-border);
  border-radius: 12px;
  font-size: 1rem;
  background: #fafafa;
  transition: border-color 0.2s, background 0.2s;
}

#login-form input:focus {
  border-color: var(--color-primary);
  background: #fff;
}

#login-btn {
  width: 100%;
  padding: 14px;
  background: var(--color-primary);
  color: #fff;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  margin-top: 6px;
  transition: background 0.2s, transform 0.1s;
}

#login-btn:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

#login-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.error-msg {
  width: 100%;
  padding: 10px 14px;
  background: var(--color-error-bg);
  color: var(--color-error);
  border-radius: 10px;
  font-size: 0.85rem;
  text-align: center;
}

/* =============================================================
   チャット画面
   ============================================================= */
#chat-screen {
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  background: transparent;
}

/* --- ヘッダー --- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(229, 231, 235, 0.6);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}

.header-spacer {
  width: 40px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
  transition: background 0.15s;
}

.icon-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.icon-btn:active {
  background: rgba(0, 0, 0, 0.1);
}

/* --- メッセージエリア --- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* ウェルカム画面 */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  gap: 20px;
  min-height: 60vh;
}

.welcome-logo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--color-primary-light);
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.18);
}

.welcome-text {
  font-size: 1.6rem;
  font-weight: 500;
  color: var(--color-text);
  line-height: 1.5;
  letter-spacing: 0.01em;
}

/* --- メッセージバブル --- */
.message {
  display: flex;
  max-width: 100%;
  animation: fadeInUp 0.3s ease;
}

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

.message.ai {
  justify-content: flex-start;
}

.message.user .bubble {
  background: var(--color-bubble-user);
  color: var(--color-bubble-user-text);
  padding: 12px 18px;
  border-radius: var(--radius-bubble);
  border-bottom-right-radius: 6px;
  max-width: 85%;
  font-size: 0.98rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.ai .bubble {
  background: transparent;
  color: var(--color-text);
  padding: 4px 0;
  max-width: 100%;
  font-size: 1rem;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

/* AI回答内の見出し・リスト的な装飾 */
.message.ai .bubble strong {
  font-weight: 700;
  color: var(--color-text);
}

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

/* --- ローディングドット --- */
.loading-dots {
  display: inline-flex;
  gap: 5px;
  padding: 8px 0;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-primary);
  animation: dotBounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* --- 入力エリア --- */
.input-area {
  padding: 8px 12px 16px;
  background: linear-gradient(180deg, transparent 0%, var(--color-bg-bottom) 30%);
  position: sticky;
  bottom: 0;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.input-pill {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 6px 6px 6px 18px;
  box-shadow: var(--shadow-md);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-pill:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.15);
}

#question-input {
  flex: 1;
  padding: 10px 0;
  font-size: 1rem;
  line-height: 1.5;
  resize: none;
  max-height: 140px;
  min-height: 24px;
  overflow-y: auto;
}

#question-input::placeholder {
  color: var(--color-text-light);
}

.icon-btn-inline {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.icon-btn-inline:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.icon-btn-inline.recording {
  background: var(--color-primary);
  color: #fff;
  animation: pulse 1.4s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5); }
  50%      { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.send-btn:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

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

.send-btn:disabled {
  background: var(--color-text-light);
  opacity: 1;
}

/* =============================================================
   サイドドロワー
   ============================================================= */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.drawer-overlay.open {
  opacity: 1;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  max-width: 85vw;
  height: 100dvh;
  background: var(--color-surface);
  z-index: 101;
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  transform: translateX(-100%);
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.drawer.open {
  transform: translateX(0);
}

@keyframes slideIn {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

.drawer-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--color-border);
}

.drawer-logo {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--color-primary-light);
  flex-shrink: 0;
}

.drawer-user {
  flex: 1;
  min-width: 0;
}

.drawer-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-email {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.drawer-menu {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.drawer-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  color: var(--color-text);
  text-align: left;
  transition: background 0.15s;
}

.drawer-item:hover {
  background: var(--color-primary-light);
}

.drawer-item:active {
  background: #a7f3d0;
}

.drawer-icon {
  font-size: 1.25rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.drawer-footer {
  padding: 8px 8px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--color-border);
}

.drawer-logout {
  color: var(--color-text-muted);
}

.drawer-logout:hover {
  background: #fee2e2;
  color: var(--color-error);
}

/* =============================================================
   トースト通知
   ============================================================= */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(31, 41, 55, 0.92);
  color: #fff;
  padding: 12px 22px;
  border-radius: 24px;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 200;
  animation: toastIn 0.25s ease;
  max-width: 88vw;
  text-align: center;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0);     }
}

/* =============================================================
   レスポンシブ
   ============================================================= */
@media (max-width: 480px) {
  .welcome-text {
    font-size: 1.4rem;
  }

  .message.user .bubble {
    max-width: 88%;
  }

  .input-area {
    padding-left: 8px;
    padding-right: 8px;
  }
}

@media (min-width: 768px) {
  .welcome-logo {
    width: 80px;
    height: 80px;
  }

  .welcome-text {
    font-size: 1.75rem;
  }
}

/* スクロールバーをスリムに（Webkit系のみ） */
.messages::-webkit-scrollbar,
.drawer-menu::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-thumb,
.drawer-menu::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover,
.drawer-menu::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}
