/* ChatGPT-style Design System */

:root {
  /* Light mode (default) */
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-tertiary: #ececec;
  --bg-chat: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #5d5d5d;
  --text-muted: #8e8e8e;
  --border-color: #e5e5e5;
  --accent: #10a37f;
  --accent-hover: #1a7f64;
  --user-bubble: #f7f7f8;
  --sidebar-width: 260px;
}

[data-theme="dark"] {
  --bg-primary: #212121;
  --bg-secondary: #171717;
  --bg-tertiary: #2f2f2f;
  --bg-chat: #212121;
  --text-primary: #ececec;
  --text-secondary: #b4b4b4;
  --text-muted: #8e8e8e;
  --border-color: #424242;
  --user-bubble: #2f2f2f;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
}

#app {
  display: flex;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for mobile */
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.sidebar-logo:hover {
  opacity: 0.8;
}

.sidebar-logo-img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.nav-section {
  margin-bottom: 24px;
}

.nav-section-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 8px 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  color: var(--text-secondary);
  font-size: 14px;
}

.nav-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-item-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-color);
}

/* Theme Toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.theme-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
}

/* Show moon in light mode, sun in dark mode */
.theme-toggle .sun-icon {
  display: none;
}

.theme-toggle .moon-icon {
  display: block;
}

[data-theme="dark"] .theme-toggle .sun-icon {
  display: block;
}

[data-theme="dark"] .theme-toggle .moon-icon {
  display: none;
}

.sidebar-footer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.sidebar-footer-row .theme-toggle {
  margin-left: auto;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.user-info:hover {
  background: var(--bg-tertiary);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
  color: white;
}

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

.user-name {
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-plan {
  font-size: 12px;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

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

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--border-color);
}

/* Main Chat Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-chat);
}

/* Auth Screen */
.auth-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* On small screens, allow auth content to scroll */
@media (max-height: 700px) {
  .auth-screen {
    align-items: flex-start;
    padding-top: 40px;
    padding-bottom: 40px;
  }
}

.auth-card {
  max-width: 440px;
  width: 100%;
  text-align: center;
}

.auth-logo {
  margin-bottom: 24px;
}

.auth-logo-img {
  width: 64px;
  height: 64px;
  object-fit: contain;
}

.auth-card h1 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.auth-card > p {
  color: var(--text-secondary);
}

.auth-tagline {
  font-size: 15px;
  margin-bottom: 28px;
}

.auth-features {
  list-style: none;
  text-align: left;
  margin-bottom: 32px;
  padding: 0;
}

.auth-features li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.auth-features li:last-child {
  border-bottom: none;
}

.auth-feature-icon {
  font-size: 20px;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}

.auth-features strong {
  color: var(--text-primary);
}

.auth-form-section {
  padding-top: 8px;
}

.auth-form-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.auth-footer {
  margin-top: 32px;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-footer a {
  color: var(--text-secondary);
  text-decoration: none;
}

.auth-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#auth-form input {
  padding: 14px 16px;
  font-size: 15px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  outline: none;
}

#auth-form input:focus {
  border-color: var(--accent);
}

#auth-form input::placeholder {
  color: var(--text-muted);
}

.auth-note {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-secondary);
}

.auth-note.success {
  color: var(--accent);
}

.auth-note.error {
  color: #ef4444;
}

/* Chat Screen */
.chat-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.chat-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  z-index: 10;
  background: var(--bg-chat);
  border-bottom: 1px solid var(--border-color);
}

.bot-selector {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.bot-selector:hover {
  background: var(--border-color);
}

.bot-selector-icon {
  font-size: 20px;
}

.bot-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  min-width: 280px;
  max-height: 400px;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.bot-dropdown.open {
  display: block;
}

.bot-dropdown-header {
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
}

.bot-dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
}

.bot-dropdown-item:hover {
  background: var(--bg-tertiary);
}

.bot-dropdown-item.active {
  background: var(--bg-tertiary);
}

.bot-dropdown-item-icon {
  font-size: 24px;
  width: 32px;
  text-align: center;
}

.bot-dropdown-item-info h4 {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.bot-dropdown-item-info p {
  font-size: 12px;
  color: var(--text-muted);
}

.bot-dropdown-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
}

.discover-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: 1px dashed var(--border-color);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}

.discover-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.discover-btn svg {
  flex-shrink: 0;
}

/* Discover Modal */
.discover-modal-content {
  max-width: 700px;
}

.discover-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.discover-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.discover-card:hover {
  border-color: var(--text-muted);
}

.discover-card.active {
  border-color: var(--accent);
  background: rgba(16, 163, 127, 0.08);
}

.discover-card-icon {
  font-size: 28px;
  flex-shrink: 0;
}

.discover-card-info {
  flex: 1;
  min-width: 0;
}

.discover-card-info h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.discover-card-info p {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.discover-card-status {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.discover-card.active .discover-card-status {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.discover-card-status svg {
  width: 14px;
  height: 14px;
  opacity: 0;
}

.discover-card.active .discover-card-status svg {
  opacity: 1;
}

.discover-category {
  margin-bottom: 20px;
}

.discover-category-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

@media (max-width: 600px) {
  .discover-grid {
    grid-template-columns: 1fr;
  }

  .discover-modal-content {
    padding: 24px 16px;
  }
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 70px 0 0 0;
  display: flex;
  flex-direction: column;
}

.welcome-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
}

.welcome-state.hidden {
  display: none;
}

.welcome-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.welcome-state h2 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.welcome-state p {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 400px;
}

.messages-container {
  max-width: 768px;
  margin: 0 auto;
  padding: 24px;
  width: 100%;
  overflow-x: hidden;
}

.message {
  padding: 16px 0;
}

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

.message-user .message-content {
  background: var(--user-bubble);
  padding: 12px 16px;
  border-radius: 20px;
  max-width: 70%;
}

.message-assistant {
  display: flex;
}

.message-assistant .message-content {
  max-width: 100%;
  line-height: 1.7;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message-content p {
  margin-bottom: 16px;
}

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

.message-content ul, .message-content ol {
  margin: 16px 0;
  padding-left: 24px;
}

.message-content li {
  margin-bottom: 8px;
}

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

.message-content code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 14px;
}

.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 8px 0;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out;
}

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

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

/* Chat Input */
.chat-input-area {
  padding: 16px 24px 24px;
  max-width: 768px;
  margin: 0 auto;
  width: 100%;
}

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

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

#chat-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 200px;
  padding: 8px 0;
  color: var(--text-primary);
}

#chat-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--text-muted);
  color: var(--bg-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.send-btn:not(:disabled) {
  background: var(--text-primary);
}

.send-btn:not(:disabled):hover {
  background: white;
}

.send-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.input-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 12px;
}

.hint-separator {
  opacity: 0.5;
}

.credits-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  transition: color 0.15s;
}

.credits-btn:hover {
  color: var(--accent);
  text-decoration: underline;
}

.clear-history-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  transition: color 0.15s;
}

.clear-history-btn:hover {
  color: var(--text-secondary);
  text-decoration: underline;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 32px;
  max-width: 800px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-content h2 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.modal-content > p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* Tier Cards */
.tier-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.tier-card {
  position: relative;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  background: var(--bg-tertiary);
}

.tier-card.featured {
  border-color: var(--accent);
}

.tier-card .tier-badge {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 4px;
}

.tier-card h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.tier-price {
  font-size: 36px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.tier-price span {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-muted);
}

.tier-card ul {
  list-style: none;
  text-align: left;
  margin-bottom: 20px;
}

.tier-card li {
  padding: 8px 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.tier-card li::before {
  content: "✓ ";
  color: var(--accent);
}

.tier-card .btn {
  width: 100%;
}

/* Mobile */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: left 0.3s;
  }

  .sidebar.open {
    left: 0;
  }

  .tier-cards {
    grid-template-columns: 1fr;
  }

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

  .messages-container {
    padding: 16px;
  }

  .chat-main {
    height: 100vh;
    height: 100dvh;
  }

  .chat-screen {
    height: 100%;
  }
}

/* iOS Safari fixes */
@supports (-webkit-touch-callout: none) {
  #app {
    height: -webkit-fill-available;
  }

  .chat-main {
    height: -webkit-fill-available;
  }
}
