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

/* === Color palette (CSS custom properties) === */
/* Gumroad-inspired: bold dark type, pink accent, soft pastel backgrounds */
:root {
  --color-primary: #FF90E8;
  --color-primary-dark: #e87dd1;
  --color-bg: #f7f7f7;
  --color-surface: #ffffff;
  --color-text: #1a1a2e;
  --color-text-soft: #6b6b80;
  --color-border: #e5e5e5;
  --color-message-area: #faf9fb;
  --color-assistant-bg: #f3f0ff;
  --color-user-bg: #1a1a2e;
}

/* === Base layout (mobile-first — no max-width, fills the screen) === */
body {
  font-family: -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  height: 100vh;
  height: 100dvh; /* dynamic viewport height — accounts for mobile browser bars */
}

/* App layout wraps everything — sidebar + chat side by side on desktop */
.app-layout {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
}

/* === Sidebar (mobile: slide-in drawer, desktop: always visible) === */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100%;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  z-index: 10;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.25s ease;
}

/* When hidden on mobile, slide off-screen to the left */
.sidebar.hidden {
  transform: translateX(-100%);
}

/* Dark overlay that appears behind the sidebar on mobile */
.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 9;
}

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

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

.sidebar-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
}

/* "New" button in the sidebar header */
.btn-new-chat {
  padding: 0.35rem 0.75rem;
  background: var(--color-text);
  color: var(--color-surface);
  border: none;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-new-chat:hover {
  background: #2d2d44;
}

/* Conversation list items */
.conversation-items {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.conversation-items li {
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s;
}

.conversation-items li:hover {
  background: var(--color-message-area);
}

/* Highlight the active conversation */
.conversation-items li.active {
  background: var(--color-assistant-bg);
  font-weight: 600;
}

/* === Chat container === */
.chat-container {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* === Header === */
/* Light header with pink accent border — clean but playful */
.chat-header {
  padding: 1rem 1.25rem;
  background: var(--color-surface);
  border-bottom: 3px solid var(--color-primary);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-title {
  flex: 1;
  text-align: center;
}

.chat-header h1 {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

.chat-subtitle {
  font-size: 0.75rem;
  color: var(--color-text-soft);
  margin-top: 0.15rem;
  font-weight: 500;
}

/* Hamburger button — opens sidebar on mobile */
.btn-menu {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--color-text);
  padding: 0.25rem;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* "+" button — starts new conversation on mobile */
.btn-new-chat-mobile {
  background: none;
  border: 2px solid var(--color-border);
  border-radius: 8px;
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--color-text);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s;
}

.btn-new-chat-mobile:hover {
  border-color: var(--color-primary);
}

/* === Messages area === */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--color-message-area);
}

/* === Individual messages === */
.message {
  max-width: 82%;
  padding: 0.75rem 1rem;
  border-radius: 18px;
  line-height: 1.5;
  font-size: 0.95rem;
  /* Each message slides up and fades in when it appears */
  animation: messageAppear 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.message p {
  word-wrap: break-word;
}

/* Assistant messages sit on the left with a soft lavender tint */
.message.assistant {
  background: var(--color-assistant-bg);
  color: var(--color-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

/* User messages sit on the right — dark background like the header */
.message.user {
  background: var(--color-user-bg);
  color: var(--color-surface);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

/* === Message appear animation === */
@keyframes messageAppear {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* === Thinking indicator (three animated dots) === */
.thinking-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 4px 2px;
}

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

/* Each dot starts its bounce at a slightly different time */
.thinking-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

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

/* === Input area === */
.chat-input {
  display: flex;
  padding: 0.75rem;
  gap: 0.5rem;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}

.chat-input input {
  flex: 1;
  /* min-height 44px ensures the input is easy to tap on phones */
  min-height: 44px;
  padding: 0.75rem 1rem;
  background: var(--color-message-area);
  border: 2px solid var(--color-border);
  border-radius: 12px;
  font-size: 1rem;
  color: var(--color-text);
  outline: none;
  transition: border-color 0.2s;
}

.chat-input input::placeholder {
  color: var(--color-text-soft);
}

/* Pink border when the input is focused */
.chat-input input:focus {
  border-color: var(--color-primary);
}

.chat-input button {
  /* min 44px width and height for a comfortable touch target */
  min-height: 44px;
  padding: 0 1.25rem;
  background: var(--color-text);
  color: var(--color-surface);
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.chat-input button:hover {
  background: #2d2d44;
}

/* Slight press-down effect when tapping the button */
.chat-input button:active {
  transform: scale(0.96);
}

/* === Desktop and tablet enhancement === */
@media (min-width: 640px) {
  /* Side-by-side layout: sidebar + chat */
  .app-layout {
    display: flex;
    max-width: 960px;
    margin: 0 auto;
  }

  /* Sidebar is always visible on desktop — no need for the drawer */
  .sidebar {
    position: static;
    transform: none;
    width: 280px;
    flex-shrink: 0;
    border-left: 1px solid var(--color-border);
  }

  /* Override the hidden class on desktop so sidebar stays visible */
  .sidebar.hidden {
    transform: none;
  }

  /* Never show the overlay on desktop */
  .sidebar-overlay {
    display: none !important;
  }

  /* Hide the hamburger — sidebar is always there */
  .btn-menu {
    display: none;
  }

  /* Hide the mobile "+" button — desktop has the sidebar "New" button */
  .btn-new-chat-mobile {
    display: none;
  }

  .header-title {
    text-align: center;
  }

  /* Chat fills the remaining space */
  .chat-container {
    flex: 1;
    border-right: 1px solid var(--color-border);
  }

  .message {
    max-width: 60%;
  }
}

/* === Videos page === */
.videos-page {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.videos-header {
  width: 100%;
  max-width: 640px;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--color-surface);
  border-bottom: 3px solid var(--color-primary);
}

.videos-header a {
  color: var(--color-text-soft);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.videos-header a:hover {
  color: var(--color-text);
}

.videos-header h1 {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text);
  text-align: center;
}

.videos-container {
  width: 100%;
  max-width: 640px;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Import section */
.import-section h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 0.75rem;
}

.import-form {
  display: flex;
  gap: 0.5rem;
}

.import-form input {
  flex: 1;
  min-height: 44px;
  padding: 0.75rem 1rem;
  background: var(--color-message-area);
  border: 2px solid var(--color-border);
  border-radius: 12px;
  font-size: 1rem;
  color: var(--color-text);
  outline: none;
  transition: border-color 0.2s;
}

.import-form input::placeholder {
  color: var(--color-text-soft);
}

.import-form input:focus {
  border-color: var(--color-primary);
}

.import-form button {
  min-height: 44px;
  padding: 0 1.25rem;
  background: var(--color-text);
  color: var(--color-surface);
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.import-form button:hover:not(:disabled) {
  background: #2d2d44;
}

.import-form button:active:not(:disabled) {
  transform: scale(0.96);
}

.import-form button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Import status feedback */
.import-status {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  line-height: 1.4;
  min-height: 1.4em;
}

.import-status:empty {
  display: none;
}

.import-status.processing {
  color: var(--color-text-soft);
}

.import-status.success {
  color: #2d7d46;
}

.import-status.error {
  color: #c0392b;
}

/* Video list */
.video-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--color-text-soft);
  font-size: 0.95rem;
}

.video-card {
  display: block;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  text-decoration: none;
  transition: border-color 0.15s;
}

.video-card:hover {
  border-color: var(--color-primary);
}

.video-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 0.25rem;
}

.video-card-meta {
  font-size: 0.8rem;
  color: var(--color-text-soft);
}

@media (min-width: 640px) {
  .videos-container {
    padding: 1.5rem 0;
  }
}
