/* Sam Design System — v2 */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;1,400&family=Inter:wght@400;500;600&display=swap');

:root {
  --paper: #F5F2EC;
  --paper-hi: #FBF8F2;
  --paper-deep: #EDE7DA;
  --rule: #E8E2D4;
  --rule-soft: #EFEAE0;
  --ink: #1F2933;
  --ink-soft: #5C6A78;
  --ink-muted: #8B95A1;
  --navy: #3F5165;
  --navy-hi: #4A5C70;
  --navy-fg: #F5F2EC;
  --sage: #8FA98A;
  --sage-soft: #D9E1D5;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--paper);
  color: var(--ink);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.6;
}

/* ── Login screen ── */
#identify-screen {
  position: fixed;
  inset: 0;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--s-5);
}
#identify-screen.hidden { display: none; }

.identify-card {
  background: var(--paper-hi);
  border: 1px solid var(--rule);
  border-radius: 16px;
  padding: 40px 44px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.identify-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cormorant Garamond', serif;
  font-weight: 500;
  font-size: 22px;
  color: var(--navy-fg);
  margin: 0 auto 16px;
}

.identify-card h1 {
  font-family: 'Inter', sans-serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}

.identify-card p {
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 24px;
}

.identify-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.identify-fields input {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 11px 14px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--paper-hi);
  outline: none;
  transition: border-color 0.15s;
}
.identify-fields input:focus { border-color: var(--ink-muted); }
.identify-fields input::placeholder { color: var(--ink-muted); }

#identify-btn {
  width: 100%;
  padding: 11px 22px;
  border-radius: 10px;
  background: var(--navy);
  color: var(--navy-fg);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
}
#identify-btn:hover { background: var(--navy-hi); }
#identify-btn:disabled { background: var(--ink-muted); cursor: not-allowed; }

.identify-error {
  font-size: 13px;
  color: #B0603F;
  margin-top: 10px;
  min-height: 16px;
}

.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--rule);
  background: var(--paper-hi);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  margin-bottom: 12px;
}
.google-btn:hover { background: var(--paper-deep); border-color: var(--ink-muted); }
.google-btn svg { flex-shrink: 0; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 14px;
  color: var(--ink-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
}
.auth-divider::before, .auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}

.auth-links {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 12px;
}
.auth-links a { color: var(--ink-soft); text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }

#reset-panel { margin-top: 4px; }
#reset-panel p { font-size: 13px; color: var(--ink-soft); margin-bottom: 10px; }
#reset-panel input { width: 100%; border: 1px solid var(--rule); border-radius: 10px; padding: 11px 14px; font-family: 'Inter', sans-serif; font-size: 14px; background: var(--paper-hi); outline: none; margin-bottom: 10px; }
#reset-panel input:focus { border-color: var(--ink-muted); }
#reset-btn { width: 100%; padding: 11px 22px; border-radius: 10px; background: var(--navy); color: var(--navy-fg); font-family: 'Inter', sans-serif; font-size: 14px; font-weight: 500; border: none; cursor: pointer; }
#reset-btn:hover { background: var(--navy-hi); }
#back-to-login { display: block; margin-top: 10px; font-size: 12px; color: var(--ink-soft); text-decoration: none; text-align: center; }
#back-to-login:hover { text-decoration: underline; }
.hidden { display: none !important; }

/* ── Header ── */
header {
  background: var(--paper-hi);
  border-bottom: 1px solid var(--rule);
  padding: var(--s-5) var(--s-6);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-shrink: 0;
}

.header-avatar { display: none; }

.header-info h1 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 32px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1;
}

.header-info p {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--ink-muted);
  margin-top: 2px;
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s-4);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sage);
  flex-shrink: 0;
}

#user-badge {
  font-size: 12px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 6px;
}

#planner-btn {
  font-size: 12px;
  color: var(--ink-soft);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-family: 'Inter', sans-serif;
  transition: color 0.15s;
  display: flex;
  align-items: center;
  gap: 5px;
}
#planner-btn:hover { color: var(--ink); }
#planner-btn svg { width: 14px; height: 14px; }

#switch-user-btn {
  font-size: 12px;
  color: var(--ink-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-family: 'Inter', sans-serif;
  transition: color 0.15s;
}
#switch-user-btn:hover { color: var(--ink); }

/* ── Messages ── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-7) var(--s-6) var(--s-6);
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
  align-self: center;
}
#messages::-webkit-scrollbar { width: 5px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 3px; }

.message {
  display: flex;
  flex-direction: column;
  animation: msgIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
  margin-top: var(--s-7);
}
.message:first-child { margin-top: 0; }
.message.same-author { margin-top: var(--s-2); }
.message.same-author .message-label { display: none; }

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

.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }

/* ── Labels / timestamps ── */
.message-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-muted);
  margin-bottom: var(--s-1);
  padding: 0 var(--s-1);
}
.message.user .message-label { text-align: right; }

.message-timestamp {
  font-size: 10px;
  color: var(--ink-muted);
  letter-spacing: .04em;
  margin-top: var(--s-1);
  padding: 0 var(--s-1);
  display: none;
}
.message:not(:has(+ .message.same-author)) .message-timestamp { display: block; }
.message.user .message-timestamp { text-align: right; }

/* ── Bubbles ── */
.bubble {
  max-width: 78%;
  padding: var(--s-4) var(--s-5);
  font-size: 15px;
  line-height: 1.6;
  word-wrap: break-word;
}

.message.assistant .bubble {
  background: var(--paper-deep);
  color: var(--ink);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
}

.message.user .bubble {
  background: var(--navy);
  color: var(--navy-fg);
  border-radius: 18px;
  border-bottom-right-radius: 6px;
}

/* ── Markdown ── */
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble strong { font-weight: 600; }
.bubble em { font-style: italic; }
.bubble ul, .bubble ol { padding-left: 20px; margin: 6px 0; }
.bubble li { margin: 3px 0; }
.bubble code {
  background: var(--rule-soft);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
}
.bubble pre {
  background: var(--rule-soft);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}
.bubble pre code { background: none; padding: 0; border-radius: 0; }
.bubble h1, .bubble h2, .bubble h3 { margin: 12px 0 4px; font-weight: 600; line-height: 1.3; }
.bubble h1 { font-size: 17px; }
.bubble h2 { font-size: 16px; }
.bubble h3 { font-size: 15px; }
.bubble blockquote {
  border-left: 2px solid var(--sage);
  padding-left: 14px;
  margin: 10px 0;
  color: var(--ink-soft);
  font-style: italic;
}
.bubble hr { border: none; border-top: 1px solid var(--rule); margin: 12px 0; }

/* ── Pull-quote ── */
.pull-quote {
  border-left: 2px solid var(--sage);
  padding-left: var(--s-4);
  margin: var(--s-3) 0;
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 17px;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* ── Suggestion callout ── */
.suggestion {
  background: var(--sage-soft);
  padding: var(--s-3) var(--s-4);
  border-radius: 10px;
  margin-top: var(--s-3);
}
.suggestion-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--ink-soft);
  margin-bottom: var(--s-1);
}
.suggestion-body { font-size: 13px; color: var(--ink); }

/* ── System notice ── */
.system-notice {
  text-align: center;
  max-width: 60%;
  margin: var(--s-5) auto;
  padding: var(--s-3) var(--s-5);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .16em;
  color: var(--ink-muted);
}
.system-notice.error { color: #B0603F; }

/* ── Action buttons ── */
.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: var(--s-2);
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.action-btn:hover { background: var(--rule-soft); border-color: var(--ink-muted); }
.action-btn.logged { color: var(--sage); border-color: var(--rule); background: var(--rule-soft); cursor: default; }
.action-btn.error { color: #B0603F; border-color: #B0603F; cursor: default; }

/* ── History divider ── */
.history-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--ink-muted);
  padding: var(--s-3) 0;
  margin: var(--s-5) 0;
}
.history-divider::before, .history-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}

/* ── Cursor ── */
.cursor {
  display: inline-block;
  width: 2px;
  height: 15px;
  background: var(--navy);
  margin-left: 2px;
  vertical-align: middle;
  animation: blink 0.8s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── Composer ── */
.input-wrap {
  padding: var(--s-4) var(--s-6) var(--s-5);
  flex-shrink: 0;
}

.input-inner {
  max-width: 920px;
  margin: 0 auto;
  display: flex;
  gap: var(--s-2);
  align-items: flex-end;
  background: var(--paper-hi);
  border: 1px solid var(--rule);
  border-radius: 24px;
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-5);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-inner:focus-within {
  border-color: var(--ink-muted);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

#input {
  flex: 1;
  resize: none;
  border: none;
  padding: 6px 0;
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: transparent;
  color: var(--ink);
  outline: none;
  max-height: 180px;
  min-height: 36px;
}
#input::placeholder { color: var(--ink-muted); }

#send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--navy);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
  color: var(--navy-fg);
}
#send-btn:hover { background: var(--navy-hi); }
#send-btn:disabled { background: var(--ink-muted); cursor: not-allowed; }
#send-btn svg { pointer-events: none; width: 16px; height: 16px; }

#upload-btn, #mic-btn, #voice-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--ink-muted);
  transition: background 0.15s, color 0.15s;
}
#upload-btn:hover, #mic-btn:hover, #voice-btn:hover {
  background: var(--rule-soft);
  color: var(--ink-soft);
}
#upload-btn svg, #mic-btn svg, #voice-btn svg { width: 18px; height: 18px; }

#mic-btn.listening {
  background: #fde8e8;
  color: #B0603F;
  animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(176,96,63,0.3); }
  50%       { box-shadow: 0 0 0 5px rgba(176,96,63,0); }
}

#voice-btn.active {
  background: var(--sage);
  color: var(--navy-fg);
  animation: voice-pulse 2s ease-in-out infinite;
}
@keyframes voice-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(143,169,138,0.3); }
  50%      { transform: scale(1.04); box-shadow: 0 0 0 5px rgba(143,169,138,0); }
}

/* ── Upload menu ── */
#upload-wrap { position: relative; }
#upload-menu {
  position: absolute;
  bottom: 44px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--paper-hi);
  border: 1px solid var(--rule);
  border-radius: 12px;
  z-index: 20;
  min-width: 200px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  overflow: hidden;
}
#upload-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border: none;
  background: none;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
}
#upload-menu button:hover { background: var(--rule-soft); }
#upload-menu button + button { border-top: 1px solid var(--rule); }

#upload-status {
  font-size: 11px;
  color: var(--ink-muted);
  padding: 0 4px;
  white-space: nowrap;
  align-self: center;
}
#upload-status.error { color: #B0603F; }
#upload-status.success { color: var(--sage); }

/* ── Hint below composer ── */
.hint {
  text-align: center;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-muted);
  margin-top: var(--s-2);
  max-width: 920px;
  margin-left: auto;
  margin-right: auto;
}

.footer-link {
  text-align: center;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-muted);
  margin-top: var(--s-1);
}
.footer-link a { color: var(--ink-muted); text-decoration: none; }
.footer-link a:hover { color: var(--ink-soft); }

/* ── Header buttons (avatar, mute) ── */
#avatar-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  padding: 4px;
  transition: color 0.15s;
}
#avatar-btn:hover { color: var(--ink); }
#avatar-btn.active { color: var(--sage); }

#mute-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  padding: 4px;
  transition: color 0.15s;
}
#mute-btn:hover { color: var(--ink); }
#mute-btn.muted { color: var(--rule); }

/* ── Avatar overlay ── */
#avatar-overlay { display: none; position: fixed; inset: 0; background: #0a0a0a; z-index: 200; flex-direction: column; align-items: center; justify-content: center; }
#avatar-overlay.active { display: flex; }
#avatar-video { width: 100%; max-width: 540px; max-height: 70vh; border-radius: 16px; background: #111; object-fit: cover; }
#avatar-status { color: rgba(255,255,255,0.5); font-size: 12px; margin-top: 14px; min-height: 20px; }
#avatar-controls { display: flex; gap: 16px; margin-top: 20px; align-items: center; }
#avatar-mic-btn { width: 60px; height: 60px; border-radius: 50%; background: #1f2937; border: 2px solid #374151; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #fff; transition: background 0.15s; }
#avatar-mic-btn:hover { background: #374151; }
#avatar-mic-btn.listening { background: #B0603F; border-color: #B0603F; animation: mic-pulse 1.2s ease-in-out infinite; }
#avatar-close-btn { position: absolute; top: 20px; right: 20px; width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,0.1); border: none; cursor: pointer; color: #fff; font-size: 20px; display: flex; align-items: center; justify-content: center; transition: background 0.15s; }
#avatar-close-btn:hover { background: rgba(255,255,255,0.2); }

/* ── Mobile responsive ── */
@media (max-width: 720px) {
  header { padding: var(--s-4) var(--s-5); }
  .header-info h1 { font-size: 26px; }
  .status-dot { display: none; }
  #messages { padding: var(--s-5) var(--s-4); }
  .bubble { max-width: 90%; }
  .input-wrap { padding: var(--s-3) var(--s-4) var(--s-4); }
  .input-inner { padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4); }
}
