/* ===== RESET & BASE ===== */

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

[hidden] {
  display: none !important;
}

:root {
  --teal: #0e8585;
  --teal-light: #e8f5f5;
  --teal-dark: #0a6b6b;
  --navy: #1b3a5c;
  --navy-light: #2a4f75;
  --text: #1a1a1a;
  --text-soft: #666;
  --bg: #fafaf9;
  --white: #ffffff;
  --border: #e2e2e0;
  --user-bg: #edf2f7;
  --assistant-bg: #ffffff;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --font-body: "DM Sans", system-ui, sans-serif;
  --font-display: "DM Serif Display", Georgia, serif;
}

html,
body {
  height: 100%;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
}

/* ===== HEADER ===== */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 16px;
}

.logo {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--navy);
  font-weight: 400;
  letter-spacing: -0.01em;
}

.tagline {
  font-size: 0.85rem;
  color: var(--text-soft);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.new-chat-btn,
.download-btn {
  padding: 8px 16px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--navy);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    opacity 0.15s;
}

.new-chat-btn:hover,
.download-btn:hover:not(:disabled) {
  background: var(--white);
  border-color: var(--navy);
}

/* ===== DOWNLOAD BUTTON STATE ===== */

.download-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-icon {
  display: none;
  flex-shrink: 0;
}

/* ===== DOWNLOAD POPOVER ===== */

.download-wrapper {
  position: relative;
}

.download-popover {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  z-index: 100;
  min-width: 140px;
}

.download-popover.is-open {
  display: flex;
  flex-direction: column;
}

.popover-option {
  padding: 10px 16px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}

.popover-option:hover {
  background: var(--bg);
}

/* ===== TOAST ===== */

.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--navy);
  color: var(--white);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
  z-index: 200;
  white-space: nowrap;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.coffee-link {
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--teal-dark);
  background: var(--teal-light);
  border-radius: 8px;
  text-decoration: none;
  transition: background 0.15s;
}

.coffee-link:hover {
  background: #d4eded;
}

/* ===== HAMBURGER BUTTON ===== */

.hamburger-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  background: none;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 8px;
  transition: background 0.15s;
}

.hamburger-btn:hover {
  background: var(--bg);
}

.hamburger-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--navy);
  border-radius: 2px;
  transition: opacity 0.15s;
}

/* ===== DRAWER ===== */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 199;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.drawer-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 260px;
  height: 100%;
  background: var(--white);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  z-index: 200;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  padding: 16px 0;
}

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

.drawer-close {
  align-self: flex-end;
  margin: 0 16px 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: var(--text-soft);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}

.drawer-close:hover {
  background: var(--bg);
  color: var(--text);
}

.drawer-nav {
  list-style: none;
  padding: 0 8px;
}

.drawer-nav li {
  margin-bottom: 2px;
}

.drawer-link {
  display: block;
  padding: 10px 16px;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 500;
  color: var(--navy);
  text-decoration: none;
  border-radius: 8px;
  transition: background 0.15s;
}

.drawer-link:hover {
  background: var(--teal-light);
  color: var(--teal-dark);
}

.drawer-link[data-view="chat"] {
  border-bottom: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  margin-bottom: 8px;
  padding-bottom: 14px;
}

/* ===== PAGE VIEWS ===== */

.page-view {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px;
  background: var(--bg);
}

.page-content {
  max-width: 640px;
  margin: 0 auto;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 28px;
  padding: 8px 16px;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--teal-dark);
  background: var(--teal-light);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.back-btn:hover {
  background: #d4eded;
}

.back-btn--bottom {
  margin-top: 32px;
}

.page-content h2 {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--navy);
  font-weight: 400;
  margin-bottom: 12px;
}

.page-content h3 {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  color: var(--navy);
  margin-top: 28px;
  margin-bottom: 8px;
}

.page-content p {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.7;
  margin-bottom: 12px;
}

.page-content a {
  color: var(--teal-dark);
}

.page-meta {
  font-size: 0.8rem;
  color: var(--text-soft);
  margin-bottom: 24px !important;
}

.page-content ul {
  margin: 12px 0 0 20px;
}

.page-content li {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.7;
  margin-bottom: 6px;
}

/* ===== CHAT AREA ===== */

.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

/* ===== WELCOME SCREEN ===== */

.welcome {
  max-width: 520px;
  margin: auto;
  text-align: center;
  padding: 40px 20px;
  animation: fadeIn 0.4s ease;
}

.welcome h2 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: var(--navy);
  margin-bottom: 16px;
  font-weight: 400;
}

.welcome p {
  font-size: 1rem;
  color: var(--text-soft);
  line-height: 1.6;
  margin-bottom: 8px;
}

.welcome-sub {
  font-size: 0.85rem !important;
  margin-bottom: 32px !important;
}

.starters {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 340px;
  margin: 0 auto;
}

.starter-btn {
  padding: 14px 20px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--navy);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    border-color 0.15s,
    box-shadow 0.15s,
    transform 0.1s;
}

.starter-btn:hover {
  border-color: var(--teal);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

/* ===== MESSAGES ===== */

.messages {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  padding: 16px 20px;
  border-radius: var(--radius);
  line-height: 1.65;
  font-size: 0.95rem;
  animation: slideIn 0.25s ease;
}

.message.user {
  background: var(--user-bg);
  align-self: flex-end;
  max-width: 85%;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  background: var(--assistant-bg);
  border: 1px solid var(--border);
  align-self: flex-start;
  max-width: 92%;
  box-shadow: var(--shadow-sm);
}

.message p {
  margin-bottom: 10px;
}

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

.message strong {
  font-weight: 600;
}

.message em {
  font-style: italic;
}

.message ul,
.message ol {
  margin: 8px 0 10px 20px;
}

.message li {
  margin-bottom: 4px;
}

.message table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.9rem;
}

.message th,
.message td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}

.message th {
  background: var(--bg);
  font-weight: 600;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 16px 20px;
  align-self: flex-start;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--teal);
  border-radius: 50%;
  opacity: 0.4;
  animation: blink 1.2s infinite;
}

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

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

/* ===== INPUT AREA ===== */

.input-area {
  padding: 16px 24px;
  background: var(--white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  transition: border-color 0.15s;
}

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

#userInput {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--text);
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 120px;
  padding: 4px 0;
}

#userInput::placeholder {
  color: #666;
}

.send-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--teal);
  color: var(--white);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
  transition:
    background 0.15s,
    transform 0.1s;
}

.send-btn:hover {
  background: var(--teal-dark);
}

.send-btn:active {
  transform: scale(0.95);
}

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

.input-footer {
  text-align: center;
  font-size: 0.75rem;
  color: #666;
  margin-top: 8px;
}

/* ===== ANIMATIONS ===== */

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

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

@keyframes blink {
  0%,
  60%,
  100% {
    opacity: 0.4;
  }
  30% {
    opacity: 1;
  }
}

/* ===== RESPONSIVE ===== */

@media (max-width: 640px) {
  .site-header {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .header-left {
    flex-direction: column;
    gap: 2px;
    flex: 1;
  }

  .header-right {
    width: 100%;
  }

  .coffee-link {
    flex: 1;
    text-align: center;
  }

  /* Icon-only square buttons on mobile */
  .download-btn,
  .new-chat-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
  }

  .download-wrapper {
    flex: none;
  }

  .btn-icon {
    display: block;
  }

  .btn-label {
    display: none;
  }

  .chat-container {
    padding: 16px;
  }

  .message.user {
    max-width: 92%;
  }

  .welcome {
    padding: 24px 8px;
  }

  .welcome h2 {
    font-size: 1.5rem;
  }

  .input-area {
    padding: 12px 16px;
  }

  .page-view {
    padding: 20px 16px;
  }

  .page-content h2 {
    font-size: 1.6rem;
  }
}
