:root {
  --g1: #8bbbed;
  --g2: #7a86c6;
  --g3: #7c4f9a;
  --g4: #9a3e82;
  --g5: #b25f70;
  --g6: #cd8b58;
  --green: #3f7f35;
  --mint: #6fa57c;
  --mint-soft: #e3f2ea;

  --brand: linear-gradient(90deg, var(--g1) 0%, var(--g2) 22%, var(--g3) 45%, var(--g4) 64%, var(--g5) 82%, var(--g6) 100%);
  --brand-deep: linear-gradient(120deg, #6c4a9e 0%, #8a3f86 55%, #b0606c 100%);

  --ink: #1d1830;
  --ink-2: #3b3550;
  --muted: #777188;
  --line: rgba(60, 40, 90, .10);
  --surface: rgba(255, 255, 255, .78);
  --surface-solid: #ffffff;
  --shadow-sm: 0 1px 2px rgba(40, 20, 70, .05), 0 2px 8px rgba(40, 20, 70, .05);
  --shadow: 0 2px 6px rgba(40, 20, 70, .05), 0 12px 32px -8px rgba(60, 30, 100, .14);
  --shadow-lg: 0 20px 60px -12px rgba(80, 40, 120, .28);
  --r: 18px;
  --r-sm: 12px;
  --font: "Heebo", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

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

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: #faf9fc;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

svg { display: block; }
button { font-family: inherit; }

/* ---------- ambient background ---------- */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .55; }
.b1 { width: 520px; height: 520px; background: #d9e7fb; top: -160px; left: -120px; }
.b2 { width: 460px; height: 460px; background: #f1dcea; top: 30%; right: -160px; }
.b3 { width: 520px; height: 420px; background: #d9efe3; bottom: -180px; left: 20%; opacity: .5; }
.dots {
  position: absolute; inset: 0;
  background-image: radial-gradient(rgba(124, 79, 154, .10) 1.2px, transparent 1.3px);
  background-size: 22px 22px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.7), transparent 60%);
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,.7), transparent 60%);
}

/* ---------- logo ---------- */
.nb-logo rect { transform-box: fill-box; transform-origin: center; }
.nb-logo.anim-idle rect { animation: dotIdle 4.2s var(--ease) infinite; animation-delay: var(--d); }
.nb-logo.anim-think rect { animation: dotThink 1.1s ease-in-out infinite; animation-delay: var(--d); }
@keyframes dotIdle {
  0%, 70%, 100% { opacity: 1; transform: scale(1); }
  35% { opacity: .5; transform: scale(.78); }
}
@keyframes breathe { 50% { transform: scale(1.12); box-shadow: 0 0 0 8px rgba(63,127,53,.10), 0 4px 12px -2px rgba(63,127,53,.5); } }
@keyframes dotThink {
  0%, 100% { opacity: .25; transform: scale(.65); }
  50% { opacity: 1; transform: scale(1); }
}

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px clamp(14px, 3vw, 28px);
  background: rgba(250, 249, 252, .72);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.brand-mark { width: 34px; height: 34px; }
.brand-text { display: grid; line-height: 1.15; }
.brand-text strong { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand-text span { font-size: 11.5px; color: var(--muted); }

.seg {
  position: relative; display: flex; padding: 4px; gap: 2px;
  background: rgba(255,255,255,.7);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}
.seg-glider {
  position: absolute; top: 4px; bottom: 4px; border-radius: 999px;
  background: var(--brand-deep);
  box-shadow: 0 4px 14px -4px rgba(138, 63, 134, .55);
  transition: all .35s var(--ease);
}
.seg-btn {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 6px;
  border: 0; background: none; cursor: pointer;
  padding: 7px 14px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; color: var(--ink-2);
  transition: color .25s;
}
.seg-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.seg-btn.active { color: #fff; }

.sample {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  margin: 10px auto 0; width: fit-content; max-width: calc(100% - 28px);
  padding: 6px 14px; border-radius: 999px;
  font-size: 12.5px; color: #7a5a1c; background: rgba(255, 240, 205, .8);
  border: 1px solid rgba(205, 139, 88, .25);
}
.pulse-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--g6); box-shadow: 0 0 0 0 rgba(205,139,88,.6); animation: pulse 2s infinite; flex: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(205,139,88,0); } 100% { box-shadow: 0 0 0 0 rgba(205,139,88,0); } }

/* ---------- views ---------- */
.view { display: none; max-width: 860px; margin: 0 auto; padding: 0 clamp(14px, 3vw, 28px); }
.view.active { display: block; animation: viewIn .45s var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

#view-chat.active { display: flex; flex-direction: column; min-height: calc(100vh - 64px); }

.view-head { padding: 28px 0 14px; }
.view-head h2 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.muted { color: var(--muted); margin: 4px 0 0; font-size: 14px; }

/* ---------- hero ---------- */
.hero { text-align: center; padding: clamp(28px, 7vh, 72px) 0 10px; transition: all .4s var(--ease); }
.hero.gone { display: none; }
.hero-logo { position: relative; width: 150px; height: 150px; margin: 0 auto 22px; }
.hero-logo .ring { position: absolute; inset: 0; width: 100%; height: 100%; }
.hero-dots { position: absolute; inset: 31px; }
.green-dot {
  position: absolute; width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #5aa04d, var(--green));
  left: 15px; bottom: 15px;
  animation: breathe 3.2s ease-in-out infinite;
  box-shadow: 0 4px 12px -2px rgba(63, 127, 53, .5);
}
.hero h1 {
  margin: 0; font-size: clamp(28px, 5vw, 40px); font-weight: 800; letter-spacing: -.03em;
  background: var(--brand-deep); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub { max-width: 460px; margin: 10px auto 22px; color: var(--muted); font-size: 15px; }

.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 620px; margin: 0 auto; }
.sugg {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 8px 14px; cursor: pointer;
  font-size: 13.5px; color: var(--ink-2);
  box-shadow: var(--shadow-sm);
  transition: transform .2s var(--ease), box-shadow .2s, border-color .2s;
}
.sugg:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: rgba(124, 79, 154, .3); }

/* ---------- thread ---------- */
.thread { flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 22px 0 10px; }
.thread:empty { display: none; }

.row { display: flex; gap: 10px; align-items: flex-start; animation: rowIn .4s var(--ease); }
@keyframes rowIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.row.user { justify-content: flex-start; flex-direction: row-reverse; }
.avatar {
  flex: none; width: 34px; height: 34px; border-radius: 11px;
  background: var(--surface-solid); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  display: grid; place-items: center; padding: 6px;
}
.avatar .nb-logo { width: 100%; height: 100%; }
.row-body { display: flex; flex-direction: column; gap: 10px; min-width: 0; flex: 1; align-items: flex-start; }
.row.user .row-body { align-items: flex-end; }

.bubble {
  padding: 11px 15px; border-radius: 16px; max-width: min(560px, 100%);
  white-space: pre-wrap; word-wrap: break-word;
}
.row.user .bubble { background: var(--brand-deep); color: #fff; border-top-left-radius: 5px; box-shadow: 0 8px 20px -10px rgba(138, 63, 134, .6); }
.row.bot .bubble { background: var(--surface-solid); border: 1px solid var(--line); border-top-right-radius: 5px; box-shadow: var(--shadow-sm); }
.bubble.error { background: #fff3f3 !important; border-color: #f3caca !important; }
.thinking { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13.5px; }
.thinking .nb-logo { width: 26px; height: 26px; }

.options { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  border: 1px solid rgba(124, 79, 154, .25); background: rgba(255,255,255,.9);
  color: var(--g3); font-weight: 600; font-size: 13.5px;
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  transition: all .2s var(--ease);
}
.opt:hover { background: var(--g3); color: #fff; border-color: var(--g3); transform: translateY(-1px); }

/* ---------- composer ---------- */
.composer-wrap { position: sticky; bottom: 0; padding: 10px 0 16px; }
.chatting .composer-wrap { background: linear-gradient(to top, #faf9fc 65%, rgba(250,249,252,0)); }
.composer {
  position: relative; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 8px 8px 8px; padding-inline-start: 18px;
  border-radius: 22px; background: var(--surface-solid);
  box-shadow: var(--shadow-lg);
}
.composer::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1.6px;
  background: var(--brand);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  opacity: .55; transition: opacity .25s; pointer-events: none;
}
.composer:focus-within::before { opacity: 1; }
.composer textarea {
  flex: 1; border: 0; outline: 0; resize: none; background: none;
  font: inherit; font-size: 16px; color: var(--ink);
  padding: 9px 0; max-height: 160px; line-height: 1.5;
}
.composer textarea::placeholder { color: #a39db2; }
#composer-send {
  flex: none; width: 42px; height: 42px; border-radius: 14px; border: 0; cursor: pointer;
  background: var(--brand-deep); color: #fff; display: grid; place-items: center;
  box-shadow: 0 6px 16px -6px rgba(138, 63, 134, .7);
  transition: transform .2s var(--ease), opacity .2s;
}
#composer-send:hover { transform: scale(1.06); }
#composer-send:disabled { opacity: .45; transform: none; cursor: default; }
#composer-send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.composer-foot { display: flex; align-items: center; gap: 10px; justify-content: center; margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.mode-badge { padding: 2px 9px; border-radius: 999px; background: var(--mint-soft); color: var(--green); font-weight: 600; }
.ghost-link { border: 0; background: none; color: var(--g3); font-size: 12px; font-weight: 600; cursor: pointer; padding: 0; }
.ghost-link:hover { text-decoration: underline; }

/* ---------- message card ---------- */
.card {
  background: var(--surface-solid); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow);
  width: 100%; max-width: 620px; overflow: hidden;
  transition: box-shadow .25s, transform .25s var(--ease);
}
.grid .card { max-width: none; }
.grid .card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.card-accent { height: 3px; background: var(--brand); }
.card-in { padding: 14px 16px 14px; }
.card-head { display: flex; align-items: center; gap: 10px; }
.cat-badge {
  width: 32px; height: 32px; flex: none; border-radius: 10px;
  display: grid; place-items: center; font-size: 16px;
  background: linear-gradient(135deg, #eef3fd, #f6ecf3);
}
.card-title { margin: 0; font-size: 15.5px; font-weight: 700; letter-spacing: -.01em; }
.card-cat { font-size: 11.5px; color: var(--muted); }
.fields { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.fields input {
  flex: 1 1 130px; min-width: 0; padding: 7px 10px; font: inherit; font-size: 13px;
  border: 1px solid var(--line); border-radius: 10px; background: #fbfafd;
  transition: border-color .2s, box-shadow .2s;
}
.fields input:focus { outline: 0; border-color: var(--g2); box-shadow: 0 0 0 3px rgba(122, 134, 198, .18); background: #fff; }
.msg-text {
  margin: 12px 0 0; padding: 12px 14px; border-radius: var(--r-sm);
  background: #f8f6fb; white-space: pre-wrap; font-size: 14.5px; line-height: 1.65; color: var(--ink-2);
}
.ph { background: rgba(205, 139, 88, .16); color: #8a4f22; border-radius: 5px; padding: 0 4px; font-weight: 500; }
.ph.filled { background: var(--mint-soft); color: var(--green); }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.note { font-size: 11.5px; color: var(--muted); }
.copy {
  display: inline-flex; align-items: center; gap: 7px;
  border: 0; cursor: pointer; padding: 8px 16px; border-radius: 11px;
  background: var(--ink); color: #fff; font-weight: 600; font-size: 13.5px;
  transition: background .25s, transform .2s var(--ease);
}
.copy:hover { transform: translateY(-1px); background: #2d2545; }
.copy svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.copy.done { background: var(--green); }

/* ---------- library ---------- */
.search {
  position: relative; display: flex; align-items: center;
  background: var(--surface-solid); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-sm); padding-inline-start: 14px;
}
.search svg { width: 19px; height: 19px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search input { flex: 1; border: 0; outline: 0; background: none; font: inherit; font-size: 15px; padding: 13px 12px; }
.search:focus-within { border-color: var(--g2); box-shadow: 0 0 0 4px rgba(122, 134, 198, .15); }
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 14px 0 16px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  border-radius: 999px; padding: 6px 13px; font-size: 13px; font-weight: 500; color: var(--ink-2);
  transition: all .2s;
}
.chip:hover { border-color: rgba(124, 79, 154, .35); }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; padding-bottom: 40px; }
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- calculator ---------- */
.calc { padding: 0; }
.calc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; padding: 16px; }
.calc label { display: grid; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.calc select, .calc input {
  font: inherit; font-size: 15px; color: var(--ink); font-weight: 500;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; background: #fbfafd;
}
.calc select:focus, .calc input:focus { outline: 0; border-color: var(--g2); box-shadow: 0 0 0 3px rgba(122, 134, 198, .18); background: #fff; }
.calc-result {
  margin: 0 16px 16px; padding: 18px; border-radius: 14px; position: relative; overflow: hidden;
  background: linear-gradient(135deg, #f1f6fe 0%, #f6eef6 55%, #fbf1e8 100%);
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}
.calc-result.none { background: #f6f4f8; }
.calc-amount { font-size: 38px; font-weight: 800; letter-spacing: -.03em; line-height: 1;
  background: var(--brand-deep); -webkit-background-clip: text; background-clip: text; color: transparent; }
.calc-result.none .calc-amount { background: none; color: var(--muted); }
.calc-label { font-size: 12px; font-weight: 700; color: var(--g3); text-transform: uppercase; letter-spacing: .04em; }
.calc-how { font-size: 13px; color: var(--muted); margin-top: 4px; }
.calc-pill { font-size: 12.5px; font-weight: 600; padding: 5px 11px; border-radius: 999px; background: rgba(255,255,255,.8); color: var(--ink-2); }
.calc-note { font-size: 11.5px; color: var(--muted); padding: 0 16px 14px; margin: -4px 0 0; }
.calc-msg { padding: 0 16px 16px; }
.calc-msg .card { box-shadow: none; max-width: none; }
#calc-slot { padding-bottom: 40px; }
#calc-slot .card { max-width: none; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-lg); z-index: 50;
  animation: toastIn .3s var(--ease);
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---------- narrow (side panel) ---------- */
@media (max-width: 520px) {
  .brand-text span { display: none; }
  .seg-btn { padding: 7px 10px; }
  .seg-btn span { display: none; }
  .seg-btn.active span { display: inline; }
  .hero-logo { width: 120px; height: 120px; }
  .hero-dots { inset: 25px; }
  .green-dot { width: 18px; height: 18px; left: 12px; bottom: 12px; }
  .grid { grid-template-columns: 1fr; }
  .avatar { width: 28px; height: 28px; border-radius: 9px; padding: 5px; }
  .calc-amount { font-size: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- embedded in side panel / demo ---------- */
.embed .sample { display: none; }
.embed .hero { padding-top: 22px; }
