/* ============================================================
   Otheri — clean, modern, native reading feel. Otheri's replies
   stay neutral/quiet; the color identity (clay) lives only on
   the user's side, so it doesn't compete for attention. System
   font stack for crisp, natural on-screen legibility.
   ============================================================ */

:root {
  --bg: #ffffff;
  --page-bg: #F9F7F4;        /* warm, quiet page canvas - keeps white surfaces (composer, cards) feeling elevated */
  --surface-hover: #F1EEE9;
  --text: #1a1a1a;
  --muted: #68686d;
  --faint: #a3a3a8;
  --border: #ececea;

  --otheri: #1f5c4a;         /* deep emerald — Otheri's signature */
  --otheri-tint: #e7f2ed;    /* light emerald surface for its turns */
  --otheri-tint-strong: #d7ebe3;

  --clay: #a15a34;           /* warm clay — the user's signature */
  --clay-tint: #f7ece2;      /* light clay surface for user turns */

  --error: #b3543f;
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow-x: hidden; }

body {
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  font-weight: 400;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--otheri-tint-strong); color: var(--otheri); }

#app { min-height: 100%; }

/* Pre-auth screens (login/signup/onboarding) - centered, no shell */
.auth-screen { max-width: 480px; margin: 0 auto; padding: 64px 24px 80px; }

/* ---------- App shell: sidebar + main ---------- */

.app-shell { display: flex; height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: width 0.18s ease, padding 0.18s ease;
  background: var(--page-bg);
  z-index: 20;
}

.sidebar.collapsed { width: 68px; padding: 20px 10px; }
.sidebar.collapsed .nav-text,
.sidebar.collapsed .sidebar-recents,
.sidebar.collapsed .brand-text { display: none; }
.sidebar.collapsed .sidebar-top { justify-content: center; }
.sidebar.collapsed .nav-item { justify-content: center; }

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 20px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.sidebar-brand .mark { width: 9px; height: 9px; border-radius: 50%; background: var(--otheri); flex-shrink: 0; }
.brand-text { font-weight: 800; font-size: 15px; color: var(--text); }

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--faint);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
}
.sidebar-toggle:hover { background: var(--surface-hover); color: var(--text); }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; margin-top: 16px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: 8px;
  background: none;
  border: none;
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  margin: 0;
  width: 100%;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); opacity: 1; }
.nav-item.active { background: var(--clay-tint); color: var(--clay); }
.nav-item svg { flex-shrink: 0; }

.sidebar-recents {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.sidebar-recents-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  font-weight: 500;
  padding: 0 10px 8px;
}

.recent-item {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.recent-item:hover { background: var(--surface-hover); color: var(--text); }

.sidebar-bottom { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }

.sidebar-backdrop { display: none; }

.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  color: var(--text);
  border: none;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  margin: 0;
}
.mobile-menu-btn:hover { background: var(--surface-hover); }

.mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--page-bg);
  z-index: 25;
}
.mobile-topbar-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-content { flex: 1; min-width: 0; height: 100%; overflow-y: auto; scroll-behavior: smooth; }
.main-inner { width: min(92%, 840px); margin: 0 auto; padding: 48px 0 40px; display: flex; flex-direction: column; min-height: 100%; }

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,0.08);
    transition: transform 0.24s ease;
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar.collapsed { width: 232px; padding: 20px 14px; } /* no collapsed rail on mobile */
  .sidebar.collapsed .nav-text,
  .sidebar.collapsed .sidebar-recents,
  .sidebar.collapsed .brand-text { display: block; }
  .sidebar.collapsed .nav-item { justify-content: flex-start; }
  .sidebar-toggle { display: none; }
  .mobile-topbar { display: flex; transition: transform 0.24s ease; }
  .mobile-topbar.pushed { transform: translateX(232px); }
  .mobile-menu-btn { display: flex; }
  .sidebar-backdrop.mobile-open {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.25);
    z-index: 15;
  }
  .main-inner { width: 100%; padding: 28px 20px 40px; }
}

/* ---------- Type ---------- */

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand .mark {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--otheri);
  display: inline-block;
}

h1 {
  font-weight: 700;
  font-size: 28px;
  letter-spacing: -0.02em;
  margin: 20px 0 10px;
  color: var(--text);
}

.tagline { color: var(--muted); font-size: 15px; margin-bottom: 44px; line-height: 1.6; font-weight: 400; }

/* ---------- Forms ---------- */

form { display: flex; flex-direction: column; gap: 2px; }

.field-block { margin-bottom: 20px; }

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
  display: block;
}

input, textarea {
  width: 100%;
  background: var(--bg);
  border: 1.5px solid var(--border);
  color: var(--text);
  padding: 13px 15px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--otheri);
  box-shadow: 0 0 0 3px var(--otheri-tint);
}

textarea { min-height: 84px; resize: vertical; line-height: 1.55; }

button {
  background: var(--otheri);
  color: #ffffff;
  border: none;
  padding: 13px 22px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 14px;
  transition: opacity 0.15s ease;
  font-family: inherit;
}

button:hover { opacity: 0.88; }
button:disabled { opacity: 0.4; cursor: default; }

button.secondary {
  background: transparent;
  color: var(--muted);
  border: 1.5px solid var(--border);
  font-weight: 600;
}
button.secondary:hover { color: var(--text); border-color: var(--faint); opacity: 1; background: var(--surface-hover); }

.error { color: var(--error); font-size: 13px; margin: 2px 0 4px; font-weight: 500; }

.link-row { text-align: center; margin-top: 32px; font-size: 14px; color: var(--muted); font-weight: 500; }
.link-row a { color: var(--otheri); cursor: pointer; text-decoration: none; font-weight: 700; }
.link-row a:hover { text-decoration: underline; }

/* ---------- Chat / check-in ---------- */

/* ---------- History ---------- */

.history-item {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.history-item:hover { opacity: 0.7; }
.history-date { font-weight: 700; font-size: 14px; margin-bottom: 6px; color: var(--text); }
.history-summary { color: var(--muted); font-size: 14px; line-height: 1.55; }

/* ---------- Journal ---------- */

.journal-entry {
  padding: 22px 0;
  border-bottom: 1px solid var(--border);
}
.journal-entry-date { font-weight: 700; font-size: 14px; margin-bottom: 8px; color: var(--text); }
.journal-entry-body {
  color: var(--text);
  font-family: 'Merriweather', Georgia, 'Times New Roman', serif;
  font-size: 15px;
  line-height: 1.7;
  letter-spacing: -0.011em;
}
.journal-entry.collapsed { cursor: pointer; }
.journal-entry.collapsed:hover .journal-entry-body { opacity: 0.75; }
.journal-month-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  margin: 28px 0 4px;
}
.journal-month-label:first-child { margin-top: 0; }

.journal-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
}
.journal-tab {
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 0 4px 10px;
  margin: 0 12px 0 0;
  margin-top: 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.journal-tab:hover { color: var(--text); opacity: 1; }
.journal-tab.active { color: var(--clay); border-bottom-color: var(--clay); font-weight: 600; }

.thread-group { margin-bottom: 32px; }
.thread-group-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}
.thread-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.thread-item-content { font-size: 15px; color: var(--text); line-height: 1.5; margin-bottom: 4px; }
.thread-item-meta { font-size: 13px; color: var(--faint); }
.thread-quiet { color: var(--muted); font-style: italic; }


.entry-date {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--page-bg);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  font-weight: 500;
  text-align: right;
  padding: 14px 4% 14px 0;
  margin: -48px 0 24px;
}

@media (max-width: 860px) {
  .entry-date { display: none; }
}

#chatLog { display: flex; flex-direction: column; gap: 36px; margin-bottom: 32px; width: 92%; margin-left: auto; margin-right: auto; }
@media (max-width: 860px) {
  #chatLog { margin-top: 4px; width: 100%; }
}

.turn { max-width: 88%; }

.turn-label {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.turn.assistant {
  background: transparent;
  padding: 0;
}
.turn.assistant .turn-label { color: var(--faint); }
.turn.assistant .turn-body {
  color: var(--text);
  font-family: 'Merriweather', Georgia, 'Times New Roman', serif;
  font-weight: 400;
  font-size: 16px;
  line-height: 1.65;
  letter-spacing: -0.011em;
}

.thinking-dots { display: inline-flex; gap: 4px; align-items: center; height: 22px; }
.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
  animation: thinking-bounce 1.2s infinite ease-in-out;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes thinking-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

@keyframes reveal-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.turn-body p.reveal-in { animation: reveal-in 0.4s ease; }

@keyframes context-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.context-transition { animation: context-fade-in 0.5s ease; }

.onboarding-choice {
  animation: context-fade-in 0.5s ease;
  padding-top: 8vh;
}
.onboarding-choice h1 { margin-bottom: 10px; }
.onboarding-choice .tagline { margin-bottom: 32px; }
.onboarding-choice-actions { display: flex; gap: 12px; }
.onboarding-choice-actions button { margin-top: 0; }

.turn.user {
  background: var(--clay-tint);
  border-radius: 18px 18px 4px 18px;
  padding: 14px 18px;
  margin-left: auto;
}
.turn.user .turn-label { color: var(--clay); justify-content: flex-end; }
.turn.user .turn-body {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 400;
}

.turn-body p { margin: 0 0 14px; white-space: pre-wrap; }
.turn-body p:last-child { margin-bottom: 0; }

.closing-summary {
  background: var(--surface-hover);
  border-radius: 18px;
  padding: 22px 24px;
  margin: 32px 0;
  border-left: 3px solid var(--otheri);
}

.closing-summary .turn-label { color: var(--muted); margin-bottom: 10px; }
.closing-summary p {
  margin: 0;
  color: var(--text);
  font-family: 'Merriweather', Georgia, 'Times New Roman', serif;
  font-weight: 400;
  font-size: 16px;
  line-height: 1.65;
  letter-spacing: -0.011em;
}

#chatInputRow {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  padding: 28px 0 20px;
  background: linear-gradient(to top, var(--page-bg) 75%, transparent);
}

.input-inner {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 18px;
  padding: 12px 12px 10px 18px;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.06);
  transition: box-shadow 0.15s ease;
}

.input-inner:focus-within { box-shadow: 0 4px 22px rgba(161, 90, 52, 0.22); }

.input-controls-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}
.input-controls-right { display: flex; align-items: center; gap: 8px; }
.input-controls-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

#chatInput {
  width: 100%;
  border: none;
  background: transparent;
  padding: 6px 0 8px;
  min-height: 24px;
  max-height: 160px;
  resize: none;
  overflow-y: hidden;
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  font-weight: 400;
  color: var(--text);
}
#chatInput.scrollable { overflow-y: auto; }
#chatInput:focus { outline: none; box-shadow: none; }

#sendBtn {
  flex-shrink: 0;
  margin-top: 0;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--clay);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}
#sendBtn:hover:not(:disabled) { background: #8a4b2a; }
#sendBtn:disabled {
  background: var(--clay-tint);
  color: var(--clay);
  opacity: 0.55;
  cursor: default;
}

#micBtn {
  flex-shrink: 0;
  margin-top: 0;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
#micBtn:hover { background: var(--surface-hover); color: var(--text); }
#micBtn.recording {
  background: var(--clay);
  color: #fff;
  animation: mic-pulse 1.6s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(161, 90, 52, 0.35); }
  50% { box-shadow: 0 0 0 6px rgba(161, 90, 52, 0); }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-card {
  background: var(--bg);
  border-radius: 16px;
  padding: 28px 28px 24px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  position: relative;
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.modal-close:hover { background: var(--surface-hover); color: var(--text); }
.modal-card h2 { margin: 0 0 14px; font-size: 18px; }
.modal-card p { font-size: 14px; line-height: 1.55; color: var(--muted); margin: 0 0 12px; }
.modal-card p:last-of-type { margin-bottom: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.modal-actions button { font-size: 14px; padding: 8px 16px; }

.wrap-up-link {
  display: inline-flex;
  align-items: center;
  height: 38px;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
  padding: 0 10px;
  margin-top: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.wrap-up-link:hover:not(:disabled) { color: var(--text); opacity: 1; background: var(--surface-hover); }
.wrap-up-link svg { flex-shrink: 0; }

.muted-note {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  margin-top: 24px;
  font-weight: 500;
}

@media (max-width: 480px) {
  #app { padding: 40px 20px 170px; }
  h1 { font-size: 24px; }
  .turn { max-width: 94%; }
}
