/* ─── Hanna AI Chat Widget ─── Circus Stretching brand DNA ───
   Warm pastels: peach, terracotta, sage. Feminine, not childish. */
:root {
  --cream: #fbf6ef;
  --cream-card: #fdfaf4;
  --peach: #f6dfd0;
  --peach-deep: #efc9b2;
  --terra: #c0603a;
  --terra-deep: #a64d2e;
  --terra-dark: #8a3c22;
  --sage: #8da37c;
  --sage-deep: #6f8560;
  --ink: #34281f;
  --muted: rgba(52, 40, 31, 0.55);
  --line: rgba(52, 40, 31, 0.10);
  --line-soft: rgba(52, 40, 31, 0.06);
  --serif: 'Playfair Display', Georgia, serif;
  --sans: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  --shadow-bubble: 0 1px 2px rgba(52, 40, 31, 0.04), 0 4px 12px rgba(52, 40, 31, 0.06);
  --shadow-user: 0 2px 6px rgba(166, 77, 46, 0.24);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--sans);
  background:
    radial-gradient(ellipse at top, rgba(239, 201, 178, 0.35), transparent 60%),
    radial-gradient(ellipse at bottom, rgba(141, 163, 124, 0.12), transparent 50%),
    linear-gradient(180deg, #f3e7da 0%, #ecdccb 100%);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

#root {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
}

/* The chat itself is a centered card */
.hn-shell {
  width: 100%;
  max-width: 760px;
  height: calc(100vh - 48px);
  max-height: 860px;
  background: var(--cream);
  border-radius: 22px;
  border: 1px solid var(--line);
  box-shadow:
    0 1px 2px rgba(52, 40, 31, 0.04),
    0 8px 24px rgba(52, 40, 31, 0.08),
    0 32px 64px rgba(52, 40, 31, 0.10);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

/* ─── Header ─── */
.hn-header {
  padding: 20px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--cream-card) 0%, var(--cream) 100%);
  display: flex; align-items: center; gap: 16px;
  flex-shrink: 0;
  position: relative;
}
.hn-header::after {
  content: '';
  position: absolute;
  left: 28px; right: 28px; bottom: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--peach-deep), transparent);
  opacity: 0.7;
}
.hn-title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 700;
  font-size: 24px;
  color: var(--ink);
  line-height: 1;
  letter-spacing: -0.01em;
}
.hn-subtitle {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--terra-deep);
  margin-top: 6px;
}

/* Quota meter — pill + live progress bar */
.hn-quota {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  background: rgba(141, 163, 124, 0.10);
  padding: 7px 12px 8px;
  border-radius: 12px;
  border: 1px solid rgba(141, 163, 124, 0.30);
  min-width: 108px;
}
.hn-quota-num {
  font-size: 11.5px;
  color: var(--sage-deep);
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.hn-quota-bar {
  display: block;
  width: 100%;
  height: 4px;
  background: rgba(52, 40, 31, 0.08);
  border-radius: 2px;
  overflow: hidden;
}
.hn-quota-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--sage), var(--sage-deep));
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* ─── Messages ─── */
.hn-scroll {
  flex: 1; overflow-y: auto;
  padding: 28px 28px 12px;
  display: flex; flex-direction: column; gap: 22px;
  scroll-behavior: smooth;
}
.hn-msg {
  max-width: 78%;
  line-height: 1.6;
  font-size: 15.5px;
  animation: hn-fadeIn 0.3s ease-out;
}
@keyframes hn-fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.hn-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--terra) 0%, var(--terra-deep) 100%);
  color: var(--cream);
  padding: 13px 18px;
  border-radius: 20px 20px 4px 20px;
  box-shadow: var(--shadow-user);
  font-weight: 500;
  letter-spacing: 0.005em;
}
.hn-msg.hanna {
  align-self: flex-start;
  display: flex; gap: 12px; align-items: flex-start;
}
.hn-msg.hanna .hn-mini-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--terra);
  border: 2px solid var(--peach-deep);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 3px;
  box-shadow: 0 2px 6px rgba(192, 96, 58, 0.22);
}
.hn-msg.hanna .hn-mini-avatar span {
  font-family: var(--serif); font-style: italic; font-weight: 700;
  font-size: 17px; color: var(--cream); margin-top: -2px;
}
.hn-bubble {
  background: var(--cream-card);
  color: var(--ink);
  padding: 16px 20px;
  border-radius: 4px 20px 20px 20px;
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow-bubble);
  position: relative;
}
.hn-bubble.streaming::after {
  content: '▍';
  display: inline-block;
  animation: hn-blink 1s steps(2) infinite;
  color: var(--terra-deep);
  margin-left: 3px;
  font-weight: 400;
}
@keyframes hn-blink { 50% { opacity: 0; } }

/* Typing dots — shown before the first chunk arrives */
.hn-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 2px;
}
.hn-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--peach-deep);
  animation: hn-bounce 1.2s infinite ease-in-out;
}
.hn-typing span:nth-child(2) { animation-delay: 0.15s; }
.hn-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes hn-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; background: var(--terra); }
}
/* Hide the cursor while the typing dots are showing */
.hn-bubble.streaming:has(.hn-typing)::after { content: none; }

/* ─── Markdown inside bubble ─── */
.hn-bubble .hn-md-p {
  margin: 0 0 12px;
  line-height: 1.6;
}
.hn-bubble .hn-md-p:last-child { margin-bottom: 0; }
.hn-bubble strong {
  font-weight: 700;
  color: var(--ink);
}
.hn-bubble em { font-style: italic; }
.hn-bubble .hn-md-code {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: rgba(138, 60, 34, 0.07);
  color: var(--terra-dark);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(138, 60, 34, 0.1);
}
.hn-bubble .hn-md-ol,
.hn-bubble .hn-md-ul {
  margin: 4px 0 12px;
  padding-left: 22px;
}
.hn-bubble .hn-md-ol:last-child,
.hn-bubble .hn-md-ul:last-child { margin-bottom: 0; }
.hn-bubble .hn-md-ol li,
.hn-bubble .hn-md-ul li {
  margin-bottom: 6px;
  line-height: 1.55;
}
.hn-bubble .hn-md-ol li:last-child,
.hn-bubble .hn-md-ul li:last-child { margin-bottom: 0; }
.hn-bubble .hn-md-ol { list-style-type: decimal; }
.hn-bubble .hn-md-ol li::marker {
  color: var(--terra-deep);
  font-weight: 700;
}
.hn-bubble .hn-md-ul li::marker { color: var(--terra-deep); }

/* ─── Resume banner ─── */
.hn-resume {
  margin: 16px 28px 0;
  padding: 14px 18px;
  background: rgba(141, 163, 124, 0.10);
  border: 1px solid rgba(141, 163, 124, 0.35);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  font-size: 14px;
  color: var(--ink);
  font-weight: 500;
  animation: hn-fadeIn 0.3s ease-out;
  flex-shrink: 0;
}
.hn-resume-actions { display: flex; gap: 8px; flex-shrink: 0; }
.hn-resume-yes, .hn-resume-no {
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 700;
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.hn-resume-yes {
  background: var(--sage-deep);
  color: var(--cream);
  border: none;
}
.hn-resume-yes:hover { background: var(--sage); }
.hn-resume-no {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.hn-resume-no:hover { color: var(--ink); border-color: var(--ink); }

/* ─── Goal save banner ─── */
.hn-goal {
  margin: 10px 28px 0;
  padding: 12px 18px;
  background: rgba(239, 201, 178, 0.28);
  border: 1px solid var(--peach-deep);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  font-size: 13.5px;
  color: var(--ink);
  font-weight: 500;
  animation: hn-fadeIn 0.3s ease-out;
  flex-shrink: 0;
}
.hn-goal strong { color: var(--terra-deep); }
.hn-goal-actions { display: flex; gap: 8px; flex-shrink: 0; }
.hn-goal-yes, .hn-goal-no {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.hn-goal-yes {
  background: var(--terra);
  color: var(--cream);
  border: none;
}
.hn-goal-yes:hover { background: var(--terra-deep); }
.hn-goal-no {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.hn-goal-no:hover { color: var(--ink); border-color: var(--ink); }

/* ─── Suggested chips ─── */
.hn-suggest {
  display: flex; flex-wrap: wrap; gap: 10px;
  padding: 4px 28px 16px;
}
.hn-chip {
  background: rgba(141, 163, 124, 0.07);
  border: 1.5px solid var(--sage);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
  transition: all 0.18s ease;
  letter-spacing: 0.005em;
}
.hn-chip:hover {
  background: var(--sage);
  color: var(--cream);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(141, 163, 124, 0.35);
}

/* ─── Input ─── */
.hn-input-wrap {
  padding: 14px 18px 20px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-card) 100%);
  display: flex; gap: 12px; align-items: flex-end;
  flex-shrink: 0;
  position: relative;
}
.hn-input-wrap::before {
  content: '';
  position: absolute;
  left: 18px; right: 18px; top: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--peach-deep), transparent);
  opacity: 0.55;
}
.hn-input {
  flex: 1;
  background: white;
  border: 1.5px solid var(--line);
  border-radius: 24px;
  padding: 13px 20px;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  resize: none;
  min-height: 48px;
  max-height: 140px;
  line-height: 1.45;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 1px 3px rgba(52, 40, 31, 0.04);
}
.hn-input:focus {
  border-color: var(--terra);
  box-shadow: 0 0 0 3px rgba(192, 96, 58, 0.13);
}
.hn-input::placeholder { color: var(--muted); font-weight: 500; }

.hn-send {
  flex-shrink: 0;
  height: 48px;
  width: 48px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--terra) 0%, var(--terra-deep) 55%, var(--terra-dark) 100%);
  color: white;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow:
    0 2px 8px rgba(138, 60, 34, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    inset 0 -1px 0 rgba(0, 0, 0, 0.1);
  transition: transform 0.12s ease, box-shadow 0.18s ease;
}
.hn-send:hover:not(:disabled) {
  transform: translateY(-1.5px);
  box-shadow:
    0 6px 14px rgba(138, 60, 34, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}
.hn-send:active:not(:disabled) { transform: translateY(0); }
.hn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: saturate(0.6);
}
.hn-send svg {
  width: 20px; height: 20px;
  transform: rotate(-45deg);
  margin-top: 1px; margin-right: 1px;
  stroke-width: 2.5;
}

/* ─── Error + rest notices ─── */
.hn-error {
  margin: 12px 28px;
  padding: 13px 18px;
  background: rgba(166, 77, 46, 0.08);
  border: 1px solid rgba(166, 77, 46, 0.28);
  color: var(--terra-deep);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  animation: hn-fadeIn 0.25s ease-out;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.hn-retry {
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 700;
  background: var(--terra);
  color: var(--cream);
  border: none;
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.hn-retry:hover { background: var(--terra-deep); }

.hn-rest {
  margin: 12px 28px;
  padding: 14px 18px;
  background: rgba(141, 163, 124, 0.10);
  border: 1px solid rgba(141, 163, 124, 0.35);
  color: var(--sage-deep);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  animation: hn-fadeIn 0.25s ease-out;
  flex-shrink: 0;
}

/* ─── Empty state ─── */
.hn-empty {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 24px 28px 12px;
  gap: 12px;
  animation: hn-fadeIn 0.4s ease-out;
}
.hn-empty-avatar {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--terra);
  border: 2.5px solid var(--peach-deep);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(192, 96, 58, 0.30);
  flex-shrink: 0;
}
.hn-empty-avatar span {
  font-family: var(--serif); font-style: italic; font-weight: 700;
  font-size: 32px; color: var(--cream); margin-top: -3px;
}
.hn-greet {
  font-family: var(--serif); font-style: italic; font-weight: 700;
  font-size: 22px; color: var(--ink); line-height: 1.25; max-width: 440px;
  letter-spacing: -0.005em;
  margin: 0;
}
.hn-eyebrow {
  font-size: 10px; font-weight: 700; letter-spacing: 2.5px;
  text-transform: uppercase; color: var(--terra-deep);
}
.hn-prompt-hint {
  font-size: 13.5px; color: var(--muted); max-width: 400px; line-height: 1.55;
  font-weight: 500;
  margin: 0;
}

/* ─── Access Gate ─── */
.hn-gate-shell {
  height: auto;
  min-height: 0;
}
.hn-gate {
  padding: 48px 36px 44px;
  display: flex; flex-direction: column;
  align-items: center; text-align: center;
  gap: 14px;
  animation: hn-fadeIn 0.4s ease-out;
}
.hn-gate .hn-empty-avatar { margin-bottom: 4px; }
.hn-gate-title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 700;
  font-size: 30px;
  color: var(--ink);
  line-height: 1.1;
  letter-spacing: -0.01em;
  margin-top: 4px;
}
.hn-gate-subtitle {
  font-size: 14.5px;
  color: var(--muted);
  max-width: 360px;
  line-height: 1.55;
  font-weight: 500;
  margin-bottom: 8px;
}
.hn-gate-form {
  display: flex; flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 340px;
  margin-top: 4px;
}
.hn-gate-input {
  width: 100%;
  background: white;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 14px 18px;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  outline: none;
  text-align: center;
  letter-spacing: 0.04em;
  font-weight: 600;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.hn-gate-input:focus {
  border-color: var(--terra);
  box-shadow: 0 0 0 3px rgba(192, 96, 58, 0.14);
}
.hn-gate-input::placeholder {
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.hn-gate-submit {
  width: 100%;
  background: linear-gradient(135deg, var(--terra) 0%, var(--terra-deep) 55%, var(--terra-dark) 100%);
  color: white;
  border: none;
  padding: 14px 22px;
  border-radius: 12px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow:
    0 2px 8px rgba(138, 60, 34, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.12s ease, box-shadow 0.18s ease;
}
.hn-gate-submit:hover:not(:disabled) {
  transform: translateY(-1.5px);
  box-shadow:
    0 6px 14px rgba(138, 60, 34, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.hn-gate-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: saturate(0.6);
}
.hn-gate-error {
  font-size: 13px;
  color: var(--terra-deep);
  font-weight: 600;
  margin-top: 4px;
}
.hn-gate-hint {
  font-size: 13px;
  color: var(--muted);
  max-width: 320px;
  line-height: 1.5;
  margin-top: 16px;
  font-weight: 500;
}
@media (max-width: 600px) {
  .hn-gate { padding: 32px 22px 28px; gap: 12px; }
  .hn-gate-title { font-size: 26px; }
  .hn-gate-subtitle { font-size: 14px; }
  .hn-gate-input { padding: 13px 16px; font-size: 16px; }
  .hn-gate-submit { padding: 13px 18px; font-size: 12px; }
}

/* ─── Mobile ─── */
@media (max-width: 700px) {
  #root {
    padding: 0;
    align-items: stretch;
    min-height: 100vh;
    min-height: 100dvh;
  }
  .hn-shell {
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    max-width: 100%;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }
  .hn-header {
    padding: max(12px, env(safe-area-inset-top)) 16px 10px;
    gap: 10px;
  }
  .hn-header::after { left: 16px; right: 16px; }
  .hn-title { font-size: 17px; }
  .hn-subtitle { font-size: 8.5px; letter-spacing: 1.3px; margin-top: 3px; }
  .hn-quota { padding: 5px 9px 6px; min-width: 86px; gap: 3px; }
  .hn-quota-num { font-size: 9.5px; }
  .hn-scroll { padding: 14px 16px 4px; gap: 14px; }
  .hn-resume { margin: 10px 14px 0; padding: 11px 14px; font-size: 13px; flex-wrap: wrap; }
  .hn-goal { margin: 8px 14px 0; padding: 10px 14px; font-size: 12.5px; flex-wrap: wrap; }
  .hn-suggest { padding: 2px 14px 8px; gap: 6px; }
  .hn-chip { font-size: 12.5px; padding: 8px 13px; }
  .hn-msg { max-width: 90%; font-size: 14.5px; }
  .hn-msg.hanna .hn-mini-avatar { width: 28px; height: 28px; }
  .hn-msg.hanna .hn-mini-avatar span { font-size: 13px; }
  .hn-bubble { padding: 11px 14px; }
  .hn-error, .hn-rest { margin: 10px 14px; padding: 11px 14px; font-size: 13px; }
  .hn-input-wrap {
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  .hn-input {
    font-size: 16px; /* prevent iOS zoom */
    padding: 11px 16px;
    min-height: 42px;
    border-radius: 21px;
  }
  .hn-send { height: 42px; width: 42px; flex-shrink: 0; }
  .hn-send svg { width: 18px; height: 18px; }

  /* Empty state — compact for mobile */
  .hn-empty { padding: 14px 20px 2px; gap: 8px; }
  .hn-empty-avatar { width: 50px; height: 50px; border-width: 2px; }
  .hn-empty-avatar span { font-size: 25px; }
  .hn-greet {
    font-size: 18px;
    max-width: 320px;
    line-height: 1.2;
    letter-spacing: -0.01em;
  }
  .hn-eyebrow { font-size: 9px; letter-spacing: 1.8px; }
  .hn-prompt-hint { font-size: 12.5px; max-width: 300px; line-height: 1.45; }
}

/* iPhone 12-15 sweet spot */
@media (max-width: 430px) {
  .hn-greet { font-size: 17px; }
  .hn-prompt-hint { font-size: 12px; }
  .hn-empty-avatar { width: 46px; height: 46px; }
  .hn-empty-avatar span { font-size: 23px; }
  .hn-chip { font-size: 12px; padding: 7px 12px; }
}

/* ─── Scrollbar ─── */
.hn-scroll::-webkit-scrollbar { width: 8px; }
.hn-scroll::-webkit-scrollbar-track { background: transparent; }
.hn-scroll::-webkit-scrollbar-thumb {
  background: rgba(52, 40, 31, 0.12);
  border-radius: 4px;
}
.hn-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(52, 40, 31, 0.22);
}
