/* ============================================================
   app.css
   Cael — Page Layouts
   Auth, check-in flow, chat, journal, dashboard
   Mobile-first throughout
   ============================================================ */


/* ── App shell ── */
/* Wraps everything post-login */

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(80px + var(--safe-bottom));
  /* space for bottom nav */
}

/* Chat page manages its own height — don't add bottom padding */
.app-main:has(.chat-page) {
  padding-bottom: 0;
  overflow: hidden;
}

@media (min-width: 768px) {
  .app-main {
    padding-bottom: 0;
  }
}


/* ── Auth pages ── */
/* Login, signup, onboarding */

.auth-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--space-8) var(--page-pad);
  max-width: var(--max-width-narrow);
  margin: 0 auto;
  width: 100%;
}

.auth-header {
  margin-bottom: var(--space-10);
}

.auth-wordmark {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 300;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: var(--space-2);
}

.auth-tagline {
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-style: italic;
  font-weight: 300;
  color: var(--muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  color: var(--muted);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--warm-light);
}

.auth-footer {
  margin-top: var(--space-8);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--muted);
}

.auth-footer a {
  color: var(--accent);
  transition: opacity var(--transition-fast);
}

.auth-footer a:hover {
  opacity: 0.7;
}


/* ── Onboarding ── */
/* Multi-step — name, intentions, preferences */

.onboarding-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: var(--space-8) var(--page-pad);
  max-width: var(--max-width-narrow);
  margin: 0 auto;
  width: 100%;
}

.onboarding-progress {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-10);
}

.onboarding-step-dot {
  height: 2px;
  flex: 1;
  background: var(--warm-light);
  border-radius: 2px;
  transition: background var(--transition-base);
}

.onboarding-step-dot.done {
  background: var(--accent);
}

.onboarding-step-dot.active {
  background: var(--warm-mid);
}

.onboarding-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-8);
}

.onboarding-question {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 300;
  line-height: 1.15;
  color: var(--ink);
}

.onboarding-question em {
  font-style: italic;
  color: var(--accent-soft);
}

.onboarding-hint {
  font-size: var(--text-sm);
  color: var(--muted);
  line-height: 1.6;
  margin-top: calc(-1 * var(--space-4));
}

.onboarding-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-bottom: var(--space-8);
}


/* ── Check-in page ── */
/* The first screen after login */

.checkin-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-8) var(--page-pad);
  max-width: var(--max-width-narrow);
  margin: 0 auto;
  width: 100%;
}

.checkin-header {
  margin-bottom: var(--space-8);
}

.checkin-greeting {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 300;
  line-height: 1.15;
  color: var(--ink);
  margin-bottom: var(--space-2);
}

.checkin-greeting em {
  font-style: italic;
  color: var(--accent-soft);
}

.checkin-date {
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.checkin-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}

.checkin-section-label {
  font-size: var(--text-xs);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--space-4);
}

.checkin-actions {
  padding: var(--space-6) 0;
  padding-bottom: calc(var(--space-6) + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Session type pills — shown on return visits */
.session-pills {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.session-pill {
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--warm-light);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  color: var(--muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  background: none;
}

.session-pill:hover {
  border-color: var(--warm-mid);
  color: var(--ink-soft);
}

.session-pill.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(122, 104, 85, 0.06);
}


/* ── Chat page ── */

.chat-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
  /* Full height minus bottom nav on mobile */
  height: calc(100dvh - 60px - 80px - var(--safe-bottom, 0px));
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--page-pad);
  border-bottom: 1px solid var(--warm-light);
  flex-shrink: 0;
}

.chat-header-name {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 300;
  font-style: italic;
  color: var(--accent);
}

.chat-header-status {
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.chat-header-mood {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chat-header-mood-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6) var(--page-pad);
  padding-bottom: var(--space-4);
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  min-height: 0; /* critical — lets flex child scroll */
}

/* Scrollbar — subtle but visible */
.chat-body::-webkit-scrollbar {
  width: 6px;
}

.chat-body::-webkit-scrollbar-track {
  background: var(--surface-raised, #f5f0eb);
  border-radius: 3px;
}

.chat-body::-webkit-scrollbar-thumb {
  background: var(--text-muted, #b0a898);
  border-radius: 3px;
}

.chat-body::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary, #8a7e72);
}

.chat-footer {
  flex-shrink: 0;
  padding: var(--space-3) var(--page-pad);
  padding-bottom: calc(var(--space-3) + var(--safe-bottom, 0px));
  background: var(--paper);
  border-top: 1px solid var(--warm-light);
  /* Sticky to bottom of chat-page flex container */
  position: sticky;
  bottom: 0;
  z-index: 10;
}

/* Close session button — end of conversation */
.close-session-wrap {
  padding: var(--space-4) 0;
  display: flex;
  justify-content: center;
  border-top: 1px solid var(--warm-light);
}

/* Typewriter cursor */
.typewriter-cursor {
  display: inline-block;
  color: var(--accent);
  opacity: 0.7;
  animation: cursor-blink 0.8s step-end infinite;
  margin-left: 1px;
  font-size: 0.85em;
  vertical-align: baseline;
}

@keyframes cursor-blink {
  0%, 100% { opacity: 0.7; }
  50%       { opacity: 0;   }
}


/* ── Journal page ── */

.journal-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
}

.journal-header {
  padding: var(--space-6) var(--page-pad) var(--space-4);
  border-bottom: 1px solid var(--warm-light);
}

.journal-header-date {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 300;
  color: var(--ink);
}

.journal-header-meta {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-top: var(--space-2);
}

.journal-mood-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.journal-mood-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.journal-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-6) var(--page-pad);
  gap: var(--space-6);
  overflow-y: auto;
}

/* Cael's journal prompt */
.journal-prompt-wrap {
  padding: var(--space-5);
  background: var(--paper-dark);
  border-radius: var(--radius-md);
  border-left: 2px solid var(--warm-mid);
}

.journal-prompt-label {
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--space-2);
}

.journal-prompt-text {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 300;
  font-style: italic;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* Write area */
.journal-write-label {
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--space-3);
}

.journal-textarea {
  width: 100%;
  min-height: 240px;
  border: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: var(--text-md);
  font-weight: 300;
  color: var(--ink);
  line-height: 1.8;
  resize: none;
  outline: none;
  caret-color: var(--accent);
}

.journal-textarea::placeholder {
  color: var(--warm-mid);
  font-style: italic;
}

.journal-footer {
  padding: var(--space-4) var(--page-pad);
  padding-bottom: calc(var(--space-4) + var(--safe-bottom));
  border-top: 1px solid var(--warm-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
}

.journal-word-count {
  font-size: var(--text-xs);
  color: var(--muted);
  letter-spacing: 0.05em;
}

/* Past entries list */
.journal-entries {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4) var(--page-pad);
}

.journal-entry-preview {
  padding: var(--space-5);
  background: white;
  border-radius: var(--radius-md);
  border: 1px solid var(--warm-light);
  border-left: 3px solid var(--warm-light);
  cursor: pointer;
  transition: all var(--transition-base);
  text-decoration: none;
  display: block;
}

.journal-entry-preview:hover {
  border-left-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.journal-entry-date {
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--space-2);
}

.journal-entry-excerpt {
  font-size: var(--text-sm);
  color: var(--ink-soft);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.journal-entry-mood {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.journal-entry-mood-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.journal-entry-mood-label {
  font-size: var(--text-xs);
  color: var(--muted);
  letter-spacing: 0.06em;
}


/* ── Dashboard page ── */

.dashboard-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
  overflow-y: auto;
}

.dashboard-header {
  padding: var(--space-6) var(--page-pad) var(--space-4);
}

.dashboard-greeting {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 300;
  color: var(--ink);
}

.dashboard-subline {
  font-size: var(--text-sm);
  color: var(--muted);
  margin-top: var(--space-1);
}

.dashboard-body {
  flex: 1;
  padding: 0 var(--page-pad) var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

/* Mood history strip */
.mood-history {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.mood-history-label {
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.mood-strip {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
  height: 60px;
}

.mood-bar {
  flex: 1;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  min-height: 8px;
  transition: height var(--transition-slow);
  cursor: pointer;
  position: relative;
}

.mood-bar:hover::after {
  content: attr(data-label);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--ink);
  color: var(--paper);
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.mood-bar-1 { background: var(--mood-1); }
.mood-bar-2 { background: var(--mood-2); }
.mood-bar-3 { background: var(--mood-3); }
.mood-bar-4 { background: var(--mood-4); }
.mood-bar-5 { background: var(--mood-5); }
.mood-bar-empty {
  background: var(--warm-light);
  opacity: 0.5;
}

.mood-strip-dates {
  display: flex;
  gap: var(--space-2);
}

.mood-strip-date {
  flex: 1;
  font-size: 0.6rem;
  text-align: center;
  color: var(--muted);
  letter-spacing: 0.06em;
}

/* Stats row */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.stat-card {
  background: white;
  border: 1px solid var(--warm-light);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.stat-value {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 300;
  color: var(--ink);
  line-height: 1;
}

.stat-label {
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Intentions panel */
.intentions-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.intentions-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.intentions-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.intention-item {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: white;
  border: 1px solid var(--warm-light);
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
}

.intention-item-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warm-mid);
  flex-shrink: 0;
  animation: pulse 3s ease-in-out infinite;
}

.intention-item-text {
  flex: 1;
  font-size: var(--text-base);
  color: var(--ink-soft);
  font-weight: 300;
}

.intention-item-timeframe {
  font-size: var(--text-xs);
  color: var(--muted);
  letter-spacing: 0.06em;
}

.intention-complete-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--warm-light);
  background: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.intention-complete-btn:hover {
  border-color: var(--success);
  background: rgba(74, 124, 95, 0.06);
}


/* ── Settings page ── */

.settings-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: var(--max-width-narrow);
  margin: 0 auto;
  width: 100%;
  padding: var(--space-6) var(--page-pad);
  gap: var(--space-8);
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.settings-section-title {
  font-size: var(--text-xs);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--warm-light);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 0;
  gap: var(--space-4);
}

.settings-row-label {
  font-size: var(--text-base);
  color: var(--ink-soft);
  font-weight: 300;
}

.settings-row-desc {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-top: var(--space-1);
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--warm-light);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition-base);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  top: 3px;
  left: 3px;
  transition: transform var(--transition-base);
  box-shadow: var(--shadow-sm);
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}


/* ── Page transitions ── */

.page-enter {
  animation: fadeUp 0.35s ease forwards;
}

.page-exit {
  animation: fadeOut 0.2s ease forwards;
}


/* ── Desktop layout ── */

@media (min-width: 768px) {

  .app-shell {
    flex-direction: row;
  }

  /* Side nav on desktop */
  .side-nav {
    width: 220px;
    flex-shrink: 0;
    border-right: 1px solid var(--warm-light);
    padding: var(--space-8) var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
    position: sticky;
    top: 0;
    height: 100dvh;
  }

  .side-nav-brand {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 300;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
  }

  .side-nav-links {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    flex: 1;
  }

  .side-nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    color: var(--muted);
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
  }

  .side-nav-link:hover {
    background: var(--paper-dark);
    color: var(--ink-soft);
  }

  .side-nav-link.active {
    background: var(--paper-dark);
    color: var(--accent);
  }

  .side-nav-link-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--warm-light);
    transition: background var(--transition-fast);
  }

  .side-nav-link.active .side-nav-link-dot {
    background: var(--accent);
  }

  .app-main {
    flex: 1;
    overflow-y: auto;
  }

  /* Chat page manages its own scroll — app-main must not scroll */
  .app-main:has(.chat-page) {
    overflow: hidden;
    padding-bottom: 0;
  }

  .chat-page {
    height: calc(100dvh - 60px); /* just minus the top nav, no bottom nav on desktop */
  }

  .stats-row {
    grid-template-columns: 1fr 1fr 1fr 1fr;
  }

  .checkin-page,
  .auth-page,
  .onboarding-page {
    padding-top: var(--space-16);
  }
}
