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

:root {
  /* Colors */
  --bg-cream: #f5f2eb;
  --bg-white: #fff;
  --text-primary: #3d3d3d;
  --text-primary-hover: #2d2d2d;
  --text-muted: #6b6b6b;
  --text-faint: #8d8d8d;
  --border-light: #e0ddd6;
  --separator-color: #d4cfc4;
  --separator-color-faint: #e8e5de;

  /* Typography */
  --font-serif: "Iowan Old Style", "Palatino Linotype", "Georgia", serif;

  /* Layout */
  --reading-width: 90ch;
  --reading-padding: 1.5rem;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font-serif);
  background: var(--bg-cream);
  color: var(--text-primary);
  min-height: 100vh;
}

/* =============================================================================
   Utility
   ============================================================================= */

.hidden {
  display: none !important;
}

/* =============================================================================
   Landing Page
   ============================================================================= */

.landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 3rem 2rem;
  max-width: 50rem;
  margin: 0 auto;
}

.landing-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.landing-logo {
  width: 6rem;
  height: auto;
}

.landing-title {
  font-size: 2.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 1rem;
}

.landing-tagline {
  font-size: 1.25rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

#google-signin-btn {
  margin-top: 1rem;
}

.landing-footer {
  border-top: 1px solid var(--border-light);
  padding-top: 2rem;
  margin-top: 3rem;
}

.features ul {
  list-style: disc;
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}

.features li {
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.platforms {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 1rem;
}

.disclaimer {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-light);
}

.disclaimer p {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

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

.contact {
  margin-top: 1.5rem;
  font-size: 0.875rem;
  color: var(--text-faint);
}

/* =============================================================================
   App Shell
   ============================================================================= */

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-cream);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 3.5rem;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Hide sidebar toggle on desktop */
.sidebar-toggle {
  display: none;
}

.header-icon {
  width: 1.25rem;
  height: 1.25rem;
}


.header-logo-img {
  width: 1.75rem;
  height: auto;
}

.header-title {
  font-size: 1.25rem;
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.header-btn {
  padding: 0.5rem;
  border: none;
  border-radius: 0.25rem;
  background: transparent;
  cursor: pointer;
}

.header-btn:hover {
  background: var(--border-light);
}

.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* =============================================================================
   Sidebar
   ============================================================================= */

.sidebar {
  width: 16rem;
  min-width: 10rem;
  max-width: 30rem;
  overflow-y: auto;
  flex-shrink: 0;
}

.resize-handle {
  width: 0.25rem;
  cursor: col-resize;
  background: var(--border-light);
  flex-shrink: 0;
}

.resize-handle:hover,
.resize-handle.dragging {
  background: var(--separator-color);
}

.sidebar-empty {
  padding: 1.25rem;
  color: var(--text-muted);
  font-size: 1rem;
}

.conv-item {
  padding: 1rem 1.25rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item:hover {
  background: var(--border-light);
}

.conv-item.active {
  background: var(--separator-color);
}

/* =============================================================================
   Main Content
   ============================================================================= */

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.empty-state p {
  margin-bottom: 0.5rem;
}

.empty-hint {
  font-size: 0.875rem;
  color: var(--text-faint);
}

.empty-hint kbd {
  font-size: 0.75rem;
  padding: 0.125rem 0.375rem;
  border: 1px solid #ccc;
  border-radius: 0.25rem;
  background: #f0f0f0;
}

/* =============================================================================
   Chat - Reading Column
   ============================================================================= */

.chat-messages {
  flex: 1;
  overflow-y: auto;
}

.chat-reader {
  max-width: var(--reading-width);
  margin: 0 auto;
  padding: 4rem var(--reading-padding);
}

/* =============================================================================
   Chat - Separators
   ============================================================================= */

.message-user::after,
.message-assistant::after {
  content: "";
  display: block;
  height: 1px;
  background: var(--separator-color);
  width: calc(var(--reading-width) + 10ch);
  margin-left: -5ch;
}

.thoughts::after {
  content: "";
  display: block;
  height: 1px;
  background: var(--separator-color-faint);
  width: calc(var(--reading-width) - 10ch);
  margin-left: 5ch;
}

/* =============================================================================
   Chat - User Message
   ============================================================================= */

.message-user {
  margin-bottom: 2.5rem;
  padding-bottom: 2.5rem;
}

.message-user::after {
  margin-top: 2.5rem;
}

.message-user .message-role {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

/* Shared: user message content + chat input */
.message-user .message-content,
.chat-input {
  font-size: 1.25rem;
  color: var(--text-primary);
  line-height: 1.5;
  font-weight: 500;
  padding: 1rem;
  border-radius: 0.5rem;
}

/* =============================================================================
   Chat - Assistant Message (Book Typography)
   ============================================================================= */

.message-assistant {
  margin-bottom: 2.5rem;
  padding-bottom: 4rem;
}

.message-assistant::after {
  margin-top: 2.5rem;
}

.message-assistant .message-role {
  display: none;
}

.message-content {
  font-size: 1.25rem;
  line-height: 1.7;
}

.message-assistant .message-content {
  text-align: justify;
}

.message-assistant .message-content p {
  margin: 0;
  text-indent: 1.5em;
}

.message-assistant .message-content > p:first-of-type {
  text-indent: 0;
}

.message-report .message-content > p:first-of-type::first-letter {
  float: left;
  font-size: 3.5em;
  line-height: 0.8;
  padding-right: 0.1em;
  margin-top: 0.05em;
}

/* Headings */
.message-content h1,
.message-content h2,
.message-content h3 {
  text-align: center;
  font-weight: normal;
}

.message-content h1 {
  font-size: 1.625rem;
  margin: 0 0 2.25em 0;
}

.message-content h2 {
  font-size: 1.5rem;
  margin: 3em 0 1.125em 0;
}

.message-content h3 {
  font-size: 1.375rem;
  margin: 2.25em 0 0.75em 0;
}

/* Lists */
.message-content ul,
.message-content ol {
  margin: 1.5em 0 1.5em 2em;
  padding: 0;
}

.message-content li {
  font-size: 1.3125rem;
  line-height: 1.6;
  margin-bottom: 0.4em;
}

/* Inline elements */
.message-content strong {
  font-weight: 600;
}

.message-content a {
  color: var(--text-primary);
  text-decoration: underline;
}

.message-content code {
  font-family: monospace;
  background: var(--border-light);
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.875em;
}

.message-content pre {
  background: var(--border-light);
  padding: 1rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 1.5em 0;
}

.message-content pre code {
  background: none;
  padding: 0;
}

/* =============================================================================
   Chat - Thoughts (Collapsible)
   ============================================================================= */

.thoughts {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.thoughts::after {
  margin-top: 1.5rem;
}

.thoughts summary {
  cursor: pointer;
  font-style: italic;
  color: var(--text-faint);
  padding: 0.5rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.thoughts summary:hover {
  color: var(--text-muted);
}

.thoughts[open] summary {
  margin-bottom: 1.5rem;
}

.thoughts-loader {
  width: 1em;
  height: 1em;
  animation: evidence-spin 1s linear infinite;
}

.thoughts.done .thoughts-loader {
  display: none;
}

.thoughts-list {
  padding-left: 1.5rem;
  border-left: 1px solid var(--separator-color-faint);
}

.thought-item {
  line-height: 1.7;
  padding: 1rem 0;
  border-bottom: 1px solid var(--separator-color-faint);
}

.thought-item:last-child {
  border-bottom: none;
}

/* =============================================================================
   Chat - Input
   ============================================================================= */

.chat-input-area {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 1.5rem;
  border-top: 1px solid var(--separator-color);
}

.chat-input-container {
  position: relative;
  max-width: var(--reading-width);
  margin: 0 auto;
  padding: 0 var(--reading-padding);
  width: 100%;
}

.chat-input {
  display: block;
  width: 100%;
  font-family: inherit;
  border: 1px solid var(--separator-color);
  background: var(--bg-white);
  resize: none;
  overflow: hidden;
}

.chat-input:focus {
  outline: none;
  border-color: var(--text-faint);
}

.send-btn {
  position: absolute;
  left: calc(100% + 1rem);
  bottom: 0;
  font-family: inherit;
  font-size: 1rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 0.5rem;
  background: var(--text-primary);
  color: var(--bg-cream);
  cursor: pointer;
  white-space: nowrap;
}

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

.send-btn.cancel {
  background: #c44;
}

.send-btn.cancel:hover {
  background: #a33;
}

/* =============================================================================
   Follow-up & Instagram Embeds
   ============================================================================= */

.follow-up {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--separator-color-faint);
}

.follow-up h3 {
  font-size: 1.125rem;
  font-weight: normal;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.follow-up-content {
  font-size: 1.25rem;
  line-height: 1.7;
  color: var(--text-primary);
}

.follow-up-content ul {
  margin: 0;
  padding-left: 2em;
}

.follow-up-content li {
  margin-bottom: 0.5em;
}

.follow-up-content li:last-child {
  margin-bottom: 0;
}

/* =============================================================================
   Evidence Section
   ============================================================================= */

.evidence-section {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--separator-color-faint);
}

.evidence-title {
  font-size: 1.125rem;
  font-weight: normal;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.evidence-group {
  margin-bottom: 1rem;
}

.evidence-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
}

.evidence-header:hover {
  color: var(--text-primary);
}

.evidence-arrow {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.evidence-content {
  margin-top: 0.5rem;
}

/* Viewer: prev button | embeds | next button */
.evidence-viewer {
  display: flex;
  align-items: stretch;
}

/* Side nav buttons - full height */
.evidence-nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 4rem;
  padding: 0;
  border: none;
  background: var(--bg-cream);
  cursor: pointer;
}

.evidence-nav img {
  width: 2.5rem;
  height: 2.5rem;
}

.evidence-nav:hover:not(:disabled) {
  background: var(--border-light);
}

.evidence-nav:disabled {
  opacity: 0.2;
  cursor: not-allowed;
}

/* Embeds container */
.evidence-embeds {
  flex: 1;
  min-width: 0;
}

/* Each embed wrapper */
.evidence-embed-wrapper {
  position: relative;
  min-height: 25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
}

.evidence-embed-wrapper.hidden {
  display: none;
}

.evidence-embed-wrapper .instagram-media {
  margin: 0 !important;
}

/* Loader - centered in wrapper */
.evidence-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-cream);
}

.evidence-loader-icon {
  width: 2rem;
  height: 2rem;
  animation: evidence-spin 1s linear infinite;
}

@keyframes evidence-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Footer: counter + close */
.evidence-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 1rem;
  padding: 0.5rem 0;
}

.evidence-counter {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.evidence-close {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0.25rem;
  background: transparent;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
}

.evidence-close:hover {
  background: var(--border-light);
  color: var(--text-primary);
}

/* =============================================================================
   Modal
   ============================================================================= */

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

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

.modal-content {
  position: relative;
  background: var(--bg-cream);
  border: 1px solid var(--separator-color);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  padding: 3rem;
  border-radius: 0.5rem;
  width: 90vw;
  max-width: var(--reading-width);
  max-height: 80vh;
  overflow-y: auto;
}

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

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

/* =============================================================================
   Shared View
   ============================================================================= */

.shared-view {
  flex: 1;
  overflow: hidden;
}

.shared-view .chat-messages {
  height: 100%;
}

/* =============================================================================
   Toasts
   ============================================================================= */

#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.75rem 1rem;
  border-radius: 0.25rem;
  border: 1px solid var(--separator-color);
  background: var(--bg-cream);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  font-size: 0.875rem;
  animation: toast-in 0.2s ease-out;
  max-width: 24rem;
  line-height: 1.4;
}

.toast.error {
  border-color: #c44;
  background: #fef2f2;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(0.5rem); }
  to { opacity: 1; transform: translateY(0); }
}

/* =============================================================================
   Mobile (max-width: 768px)
   ============================================================================= */

/* Sidebar overlay - hidden by default */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 10;
}

.sidebar-overlay.visible {
  display: block;
}

@media (max-width: 768px) {
  /* Reduce base font size: 14px base means 1.25rem = 17.5px ≈ 18px */
  html {
    font-size: 14px;
  }

  /* Show hamburger button */
  .sidebar-toggle {
    display: block;
  }

  /* Hide resize handle */
  .resize-handle {
    display: none;
  }

  /* Sidebar: hidden drawer */
  .sidebar {
    position: fixed;
    top: 3.5rem;
    left: 0;
    bottom: 0;
    width: 90vw;
    max-width: 20rem;
    z-index: 20;
    background: var(--bg-cream);
    border-right: 1px solid var(--border-light);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

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

  /* Reading area adjustments */
  .chat-reader {
    padding: 2rem 1.25rem;
  }

  /* Left-align text to avoid rivers */
  .message-assistant .message-content {
    text-align: left;
    line-height: 1.8;
  }

  /* Remove first-line indent on mobile */
  .message-assistant .message-content p {
    text-indent: 0;
  }

  /* Adjust separator widths for mobile */
  .message-user::after,
  .message-assistant::after {
    width: 100%;
    margin-left: 0;
  }

  .thoughts::after {
    width: 100%;
    margin-left: 0;
  }

  /* Sidebar adjustments */
  .sidebar-empty {
    font-size: 1rem;
    padding: 1.25rem;
  }

  .conv-item {
    font-size: 1rem;
    padding: 1rem 1.25rem;
  }

  /* Input area */
  .chat-input-area {
    padding: 1rem;
  }

  .chat-input-container {
    padding: 0;
  }

  .send-btn {
    position: static;
    width: 100%;
    margin-top: 0.75rem;
  }

  /* Evidence section - mobile */
  .evidence-nav {
    width: 3rem;
  }

  .evidence-nav img {
    width: 2rem;
    height: 2rem;
  }

  .evidence-embed-wrapper {
    min-height: 300px;
  }
}
