/* AYANOKOJI AI — Chat Page Styles */

.chat-page { height: 100vh; display: flex; flex-direction: column; padding-top: var(--nav-height); }

/* Chat Layout */
.chat-layout { display: flex; flex: 1; overflow: hidden; position: relative; z-index: 1; }

/* Sidebar */
.chat-sidebar {
  width: 280px; background: var(--bg-secondary); border-right: 1px solid var(--border-subtle);
  display: flex; flex-direction: column; padding: 1.5rem; transition: transform var(--transition-base);
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.sidebar-header h3 { font-size: 0.9rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }
.new-chat-btn {
  width: 100%; padding: 0.75rem 1rem; background: var(--bg-tertiary); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); color: var(--text-primary); font-weight: 500; font-size: 0.9rem;
  display: flex; align-items: center; gap: 0.5rem; transition: all var(--transition-fast); cursor: pointer;
  margin-bottom: 1.5rem;
}
.new-chat-btn:hover { border-color: var(--border-hover); background: var(--bg-glass-hover); }
.chat-history { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.25rem; }
.chat-history-item {
  padding: 0.65rem 0.75rem; border-radius: var(--radius-sm); color: var(--text-secondary);
  font-size: 0.85rem; transition: all var(--transition-fast);
  display: flex; align-items: center; justify-content: flex-start; gap: 0.65rem;
}
.chat-history-title {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
.chat-delete-btn {
  background: transparent; border: none; color: var(--text-muted); cursor: pointer;
  padding: 0; display: flex; align-items: center; justify-content: center;
  opacity: 0; width: 0; overflow: hidden; transition: all 0.2s; margin-right: -0.5rem;
}
.chat-history-item:hover .chat-delete-btn {
  opacity: 0.7; width: 14px; margin-right: 0;
}
.chat-delete-btn:hover {
  color: var(--crimson); opacity: 1 !important; transform: scale(1.1);
}
@media (max-width: 768px) {
  .chat-delete-btn { opacity: 0.35; width: 14px; margin-right: 0; }
}
.chat-history-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.chat-history-item.active { background: var(--crimson-subtle); color: var(--text-primary); border-left: 2px solid var(--crimson); }

/* Credits Display */
.credits-display {
  margin-top: auto; padding: 1rem; background: var(--bg-tertiary); border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}
.credits-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.credits-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.credits-count { font-size: 1.2rem; font-weight: 700; color: var(--text-primary); }
.credits-count span { color: var(--crimson); }
.credits-bar { width: 100%; height: 4px; background: var(--bg-primary); border-radius: var(--radius-full); overflow: hidden; margin-bottom: 0.75rem; }
.credits-bar-fill { height: 100%; background: linear-gradient(90deg, var(--crimson), #ef4444); border-radius: var(--radius-full); transition: width var(--transition-base); }
.credits-upgrade { width: 100%; }

/* Chat Main Area */
.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* Chat Header Bar */
.chat-header-bar {
  display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle); background: rgba(10,10,15,0.5);
  backdrop-filter: blur(10px);
}
.chat-header-info { display: flex; align-items: center; gap: 0.75rem; }
.chat-avatar-sm { width: 36px; height: 36px; border-radius: var(--radius-sm); background: linear-gradient(135deg, var(--crimson), var(--crimson-dark)); display: flex; align-items: center; justify-content: center; font-size: 0.9rem; }
.chat-header-name { font-weight: 600; font-size: 0.95rem; }
.chat-header-status { font-size: 0.75rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.35rem; }
.chat-header-status .status-dot { width: 6px; height: 6px; border-radius: 50%; background: #22c55e; }
.sidebar-toggle-btn { display: none; background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); padding: 0.5rem; color: var(--text-secondary); cursor: pointer; }

/* Messages */
.chat-messages { flex: 1; overflow-y: auto; padding: 2rem 1.5rem; display: flex; flex-direction: column; gap: 1.5rem; scroll-behavior: smooth; }

/* Welcome Screen */
.chat-welcome {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; flex: 1; padding: 3rem;
}
.welcome-avatar { width: 80px; height: 80px; border-radius: var(--radius-lg); background: linear-gradient(135deg, var(--crimson), var(--crimson-dark)); display: flex; align-items: center; justify-content: center; font-size: 2rem; margin-bottom: 1.5rem; box-shadow: var(--shadow-glow); animation: glow 3s ease-in-out infinite; }
.welcome-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; }
.welcome-subtitle { color: var(--text-secondary); font-size: 1rem; max-width: 400px; margin-bottom: 2rem; line-height: 1.6; }
.welcome-suggestions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; max-width: 500px; width: 100%; }
.suggestion-card {
  padding: 1rem; background: var(--bg-tertiary); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); cursor: pointer; text-align: left; font-size: 0.85rem;
  color: var(--text-secondary); transition: all var(--transition-fast); line-height: 1.5;
}
.suggestion-card:hover { border-color: var(--border-hover); color: var(--text-primary); transform: translateY(-2px); }
.suggestion-icon { font-size: 1.2rem; margin-bottom: 0.5rem; display: block; }

/* Message Bubbles */
.message { display: flex; gap: 0.75rem; max-width: 85%; animation: fadeInUp 0.3s var(--ease-out); }
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.ai { align-self: flex-start; }
.message-avatar { width: 32px; height: 32px; border-radius: var(--radius-sm); flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; }
.message.ai .message-avatar { background: linear-gradient(135deg, var(--crimson), var(--crimson-dark)); }
.message.user .message-avatar { background: var(--bg-tertiary); border: 1px solid var(--border-subtle); }
.message-bubble { padding: 0.85rem 1.15rem; border-radius: var(--radius-lg); line-height: 1.6; font-size: 0.95rem; }
.message.ai .message-bubble { background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-top-left-radius: 4px; color: var(--text-primary); }
.message.user .message-bubble { background: linear-gradient(135deg, var(--crimson), #b91c1c); color: white; border-top-right-radius: 4px; }
.message-time { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.35rem; }

/* Typing Indicator */
.typing-indicator { display: flex; gap: 4px; padding: 0.85rem 1.15rem; }
.typing-dot { width: 8px; height: 8px; background: var(--text-muted); border-radius: 50%; animation: typingBounce 1.4s ease-in-out infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-8px); } }

/* Chat Input */
.chat-input-area {
  padding: 1rem 1.5rem 1.5rem; border-top: 1px solid var(--border-subtle);
  background: rgba(10,10,15,0.5); backdrop-filter: blur(10px);
}
.chat-input-wrapper {
  display: flex; align-items: flex-end; gap: 0.75rem; background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: 0.5rem 0.75rem;
  transition: all var(--transition-fast); max-width: 800px; margin: 0 auto;
}
.chat-input-wrapper:focus-within { border-color: var(--border-hover); box-shadow: 0 0 0 3px var(--crimson-subtle); }
.chat-input {
  flex: 1; padding: 0.5rem; background: transparent; color: var(--text-primary);
  font-size: 0.95rem; resize: none; min-height: 24px; max-height: 120px; line-height: 1.5;
}
.chat-input::placeholder { color: var(--text-muted); }
.chat-send-btn {
  width: 40px; height: 40px; border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--crimson), #b91c1c); color: white;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: all var(--transition-fast); cursor: pointer;
}
.chat-send-btn:hover { transform: scale(1.05); box-shadow: 0 4px 16px rgba(220,38,38,0.4); }
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.chat-disclaimer { text-align: center; font-size: 0.75rem; color: var(--text-muted); margin-top: 0.5rem; }

/* Login Prompt Modal Content */
.login-prompt-content { text-align: center; }
.login-prompt-icon { font-size: 3rem; margin-bottom: 1rem; display: block; }
.login-prompt-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.75rem; }
.login-prompt-desc { color: var(--text-secondary); font-size: 0.95rem; margin-bottom: 2rem; line-height: 1.6; }
.login-prompt-features { text-align: left; margin-bottom: 2rem; }
.login-prompt-features li { display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem 0; color: var(--text-secondary); font-size: 0.9rem; }
.login-prompt-features li::before { content: '✓'; color: var(--crimson); font-weight: 700; min-width: 16px; }
.login-prompt-actions { display: flex; flex-direction: column; gap: 0.75rem; }

/* Auth Modal */
.auth-tabs { display: flex; gap: 0; margin-bottom: 2rem; background: var(--bg-tertiary); border-radius: var(--radius-md); padding: 4px; }
.auth-tab { flex: 1; padding: 0.65rem; text-align: center; font-size: 0.9rem; font-weight: 500; color: var(--text-secondary); border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition-fast); background: none; }
.auth-tab.active { background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow-sm); }
.auth-divider { display: flex; align-items: center; gap: 1rem; margin: 1.5rem 0; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border-subtle); }
.auth-divider span { font-size: 0.8rem; color: var(--text-muted); }

/* ========================================
   CHAT PAGE — Responsive
   ======================================== */

/* Tablet */
@media (max-width: 1024px) {
  .chat-sidebar {
    width: 260px;
  }

  .welcome-suggestions {
    max-width: 450px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  /* --- Full-screen chat experience --- */
  .chat-page {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
  }

  /* --- Sidebar as overlay --- */
  .chat-sidebar {
    position: fixed;
    top: var(--nav-height);
    left: 0;
    bottom: 0;
    width: 85%;
    max-width: 320px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s var(--ease-out);
    box-shadow: none;
  }

  .chat-sidebar.active {
    transform: translateX(0);
    box-shadow: 20px 0 60px rgba(0, 0, 0, 0.5);
  }

  /* Sidebar overlay backdrop */
  .chat-sidebar.active::after {
    content: '';
    position: fixed;
    top: 0;
    left: 100%;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    pointer-events: auto;
  }

  .sidebar-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
    font-size: 1.1rem;
  }

  .new-chat-btn {
    min-height: 44px;
    font-size: 0.88rem;
  }

  .chat-history-item {
    min-height: 42px;
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    font-size: 0.88rem;
  }

  .credits-display {
    padding: 0.85rem;
  }

  /* --- Chat Header --- */
  .chat-header-bar {
    padding: 0.65rem 0.75rem;
    gap: 0.5rem;
  }

  .chat-avatar-sm {
    width: 32px;
    height: 32px;
    font-size: 0.8rem;
  }

  .chat-header-name {
    font-size: 0.88rem;
  }

  .chat-header-status {
    font-size: 0.7rem;
  }

  /* --- Welcome Screen --- */
  .chat-welcome {
    padding: 2rem 1rem;
    justify-content: flex-start;
    padding-top: 15vh;
  }

  .welcome-avatar {
    width: 64px;
    height: 64px;
    font-size: 1.5rem;
    margin-bottom: 1rem;
  }

  .welcome-title {
    font-size: 1.25rem;
  }

  .welcome-subtitle {
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 1.5rem;
  }

  .welcome-suggestions {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    max-width: 100%;
    padding: 0 0.25rem;
  }

  .suggestion-card {
    padding: 0.75rem;
    font-size: 0.78rem;
    line-height: 1.4;
    border-radius: var(--radius-md);
    min-height: 70px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .suggestion-icon {
    font-size: 1rem;
    margin-bottom: 0.3rem;
  }

  /* --- Messages --- */
  .chat-messages {
    padding: 0.75rem;
    gap: 1rem;
  }

  .message {
    max-width: 90%;
    gap: 0.5rem;
  }

  .message-avatar {
    width: 28px;
    height: 28px;
    font-size: 0.7rem;
  }

  .message-bubble {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    line-height: 1.55;
  }

  .message-time {
    font-size: 0.65rem;
    margin-top: 0.25rem;
  }

  /* Typing indicator */
  .typing-indicator {
    padding: 0.75rem 1rem;
  }

  .typing-dot {
    width: 7px;
    height: 7px;
  }

  /* --- Chat Input --- */
  .chat-input-area {
    padding: 0.5rem 0.75rem;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-subtle);
  }

  .chat-input-wrapper {
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius-md);
    gap: 0.5rem;
  }

  .chat-input {
    padding: 0.5rem 0.35rem;
    font-size: 16px; /* Prevents iOS zoom */
    min-height: 22px;
  }

  .chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
  }

  .chat-send-btn svg {
    width: 16px;
    height: 16px;
  }

  .chat-disclaimer {
    font-size: 0.65rem;
    margin-top: 0.35rem;
    padding: 0 0.25rem;
  }

  /* --- Login Prompt --- */
  .login-prompt-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
  }

  .login-prompt-title {
    font-size: 1.2rem;
  }

  .login-prompt-desc {
    font-size: 0.88rem;
    margin-bottom: 1.5rem;
  }

  .login-prompt-features li {
    font-size: 0.85rem;
    padding: 0.35rem 0;
  }

  /* --- Auth Modal --- */
  .auth-tabs {
    margin-bottom: 1.5rem;
  }

  .auth-tab {
    min-height: 42px;
    font-size: 0.88rem;
  }
}

/* Small Mobile */
@media (max-width: 480px) {
  .chat-welcome {
    padding-top: 10vh;
  }

  .welcome-suggestions {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .suggestion-card {
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    min-height: 48px;
    padding: 0.65rem 0.85rem;
  }

  .suggestion-icon {
    margin-bottom: 0;
    font-size: 1.1rem;
  }

  .message {
    max-width: 95%;
  }

  .chat-header-bar {
    padding: 0.5rem 0.5rem;
  }
}
