:root {
  --bg: #F6FAF8;
  --bg-elev: #FFFFFF;
  --bg-elev-2: #EEF5F2;
  --text: #0B1210;
  --text-dim: #5B6B66;
  --mint: #2ECC9A;
  --mint-strong: #0F9E76;
  --mint-tint: #E4FBF3;
  --user-bubble: #E4FBF3;
  --border: #E1EAE6;
  --danger: #E5484D;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(15,23,42,.05);
  --maxw: 720px;
  --sidebar-w: 280px;
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 12px; top: 12px; background: var(--mint); color: #06110d; padding: 8px 14px; border-radius: 10px; z-index: 999; }

#shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar: solution tree + recent chats ---------- */
#sidebar-scrim { display: none; }
#sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--bg-elev); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px 12px 16px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 10px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); }
.brand-mark { border-radius: 50%; flex: none; }
.wordmark { font-weight: 600; font-size: 1.05rem; letter-spacing: .2px; }
.wordmark b { font-weight: 800; color: var(--mint-strong); }
.mobile-only { display: none; }

.icon-btn {
  background: none; border: none; color: var(--text);
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-elev-2); }

.sidebar-primary-btn {
  display: flex; align-items: center; gap: 8px;
  background: var(--mint-tint); color: var(--mint-strong); border: 1px solid var(--mint);
  font-weight: 700; font-size: .88rem;
  padding: 10px 14px; border-radius: 12px; cursor: pointer; margin: 6px 2px 12px;
}
.sidebar-primary-btn:hover { background: var(--mint); color: #06120d; }

.sidebar-section-label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-dim); padding: 10px 6px 6px;
}
.solution-tree { display: flex; flex-direction: column; gap: 2px; }
.tree-group { border-radius: 10px; }
.tree-group summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 6px; border-radius: 10px; font-size: .86rem; font-weight: 700; color: var(--text);
}
.tree-group summary::-webkit-details-marker { display: none; }
.tree-group summary:hover { background: var(--bg-elev-2); }
.tree-group summary::after { content: '›'; transform: rotate(90deg); transition: transform .15s; color: var(--text-dim); }
.tree-group[open] summary::after { transform: rotate(-90deg); }
.tree-count { font-weight: 500; color: var(--text-dim); font-size: .74rem; margin-left: auto; margin-right: 6px; }
.tree-group ul { list-style: none; margin: 2px 0 6px; padding: 0 0 0 10px; display: flex; flex-direction: column; gap: 1px; }
.tree-leaf {
  width: 100%; display: flex; align-items: center; gap: 8px; text-align: left;
  background: none; border: none; color: var(--text-dim); font-size: .84rem;
  padding: 7px 8px; border-radius: 8px; cursor: pointer;
}
.tree-leaf:hover { background: var(--bg-elev-2); color: var(--text); }
.tree-leaf.active { background: var(--mint-tint); color: var(--mint-strong); font-weight: 700; }
.tree-leaf .dot { width: 6px; height: 6px; border-radius: 50%; flex: none; background: var(--mint); }
.tree-leaf .dot.academy { background: #8B5CF6; }

.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.history-list li button {
  width: 100%; text-align: left; background: none; border: none; color: var(--text);
  padding: 8px 8px; border-radius: 8px; cursor: pointer; font-size: .84rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-list li button:hover { background: var(--bg-elev-2); }
.drawer-empty { color: var(--text-dim); font-size: .8rem; padding: 2px 8px; }

/* ---------- Main column ---------- */
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

#topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(246,250,248,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
}
#switchback { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
#switchback[hidden] { display: none; }
.switchback-back {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text);
  font-weight: 700; font-size: .82rem; padding: 7px 12px; border-radius: 999px; cursor: pointer; flex: none;
}
.switchback-back:hover { border-color: var(--mint); color: var(--mint-strong); }
#switchback-title { font-size: .88rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#switchback[hidden] ~ .topbar-actions #switchback-open { display: none; }

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.pill-btn {
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text);
  font-weight: 700; font-size: .82rem; padding: 8px 14px; border-radius: 999px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center;
}
.pill-btn:hover { border-color: var(--mint); color: var(--mint-strong); }
.account-btn {
  background: var(--mint); color: #06120d; border: none;
  font-weight: 700; font-size: .88rem;
  padding: 8px 16px; border-radius: 999px; cursor: pointer;
}
.account-btn.signed-in { background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border); }

#main { min-height: calc(100vh - 60px); }

.landing { max-width: var(--maxw); margin: 0 auto; padding: 40px 18px 60px; }
.hero { text-align: center; padding: 12px 0 8px; }
.hero-mascot { display: block; margin: 0 auto 16px; filter: drop-shadow(0 8px 20px rgba(46,204,154,.35)); }
.hero h1 { font-size: clamp(1.5rem, 4vw, 2.3rem); line-height: 1.22; margin: 0 0 14px; font-weight: 800; }
.hero h1 em { font-style: normal; color: var(--mint-strong); }
.hero .lead { color: var(--text-dim); font-size: 1rem; max-width: 580px; margin: 0 auto; line-height: 1.6; }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 26px; padding: 10px 10px 10px 18px; box-shadow: var(--shadow);
}
.composer textarea {
  flex: 1; resize: none; background: none; border: none; outline: none;
  color: var(--text); font-size: 1rem; font-family: inherit; line-height: 1.4;
  max-height: 160px; padding: 6px 0;
}
.composer textarea::placeholder { color: var(--text-dim); }
.send-btn {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--mint); color: #06120d; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:disabled { opacity: .4; cursor: default; }
.composer-landing { margin: 28px auto 0; max-width: 640px; }

.chip-row {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  margin: 16px auto 0; max-width: 640px;
}
.chip {
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text);
  font-size: .84rem; padding: 8px 14px; border-radius: 999px; cursor: pointer;
}
.chip:hover { border-color: var(--mint); color: var(--mint-strong); }

.showcase-sub { color: var(--text-dim); margin: 0 0 20px; font-size: .92rem; }

.plans-teaser { margin-top: 48px; text-align: center; }
.plans-teaser h2 { font-size: 1.3rem; margin: 0 0 4px; }
.plans-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin-top: 20px;
}
.plan-card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px; padding: 20px 14px; box-shadow: var(--shadow); }
.plan-card.featured { border-color: var(--mint); box-shadow: 0 0 0 1px var(--mint) inset, var(--shadow); }
.plan-card h3 { margin: 0 0 6px; font-size: .9rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px; }
.plan-card .price { font-size: 1.5rem; font-weight: 800; margin: 0 0 4px; }
.plan-card .price span { font-size: .74rem; font-weight: 500; color: var(--text-dim); }
.plan-card p.note { color: var(--text-dim); font-size: .78rem; margin: 0; }

.soveai-footer { display: flex; align-items: center; gap: 8px; justify-content: center; padding: 30px 0 6px; opacity: .75; font-size: .82rem; }
.soveai-footer img { border-radius: 5px; }

.chat { display: flex; flex-direction: column; height: calc(100vh - 60px); max-width: var(--maxw); margin: 0 auto; width: 100%; }
.chat[hidden] { display: none; }
#thread { flex: 1; overflow-y: auto; padding: 20px 16px 10px; }
.msg { display: flex; gap: 10px; margin-bottom: 20px; max-width: 100%; }
.msg .avatar { flex: none; width: 28px; height: 28px; border-radius: 50%; margin-top: 2px; background: radial-gradient(circle at 30% 30%, #B9FFE8, var(--mint) 60%, #0d8a6c 100%); }
.msg .bubble { line-height: 1.55; font-size: .97rem; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { flex-direction: row-reverse; margin-left: auto; }
.msg.user .bubble { background: var(--user-bubble); padding: 10px 14px; border-radius: 16px; }
.msg .route-tag { display: block; margin-top: 6px; font-size: .72rem; color: var(--text-dim); }
.msg .route-tag a { color: var(--mint-strong); text-decoration: none; }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:.2} 40%{opacity:1} }

.composer-dock { padding: 10px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--bg); }
.disclaimer { text-align: center; color: var(--text-dim); font-size: .72rem; margin: 8px 0 0; }
.link-btn { background: none; border: none; color: var(--mint-strong); font-size: .72rem; padding: 0; cursor: pointer; text-decoration: underline; }

/* ---------- Solution view (right-pane live embed of a Sove site) ---------- */
.solution-view { height: calc(100vh - 60px); display: flex; flex-direction: column; position: relative; }
.solution-view[hidden] { display: none; }
.solution-frame-fallback {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 5;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 16px; box-shadow: var(--shadow); font-size: .84rem;
}
.solution-frame-fallback[hidden] { display: none; }
.solution-frame-fallback a { color: var(--mint-strong); font-weight: 700; }
#solution-frame { flex: 1; width: 100%; border: none; background: #fff; }

#notice {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 12px;
  font-size: .85rem; z-index: 60; display: none; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
#notice.show { display: block; }

dialog#modal { background: var(--bg-elev); color: var(--text); border: 1px solid var(--border); border-radius: 16px; padding: 24px; max-width: 380px; width: calc(100vw - 40px); }
dialog#modal::backdrop { background: rgba(15,23,42,.35); }
dialog#modal h2 { margin-top: 0; }
dialog#modal h3 { font-size: .9rem; margin: 16px 0 6px; }
dialog#modal .note { color: var(--text-dim); font-size: .88rem; }
dialog#modal .button { display: inline-block; background: var(--mint); color: #06120d; font-weight: 700; padding: 10px 18px; border-radius: 999px; text-decoration: none; margin-top: 10px; border: none; cursor: pointer; }
dialog#modal .row { display: flex; gap: 10px; margin-top: 14px; }
dialog#modal input { width: 100%; margin: 4px 0 10px; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
dialog#modal label { font-size: .82rem; color: var(--text-dim); }
.memory-list { padding-left: 18px; margin: 4px 0 10px; font-size: .86rem; }

/* ---------- Download apps modal ---------- */
.dl-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.dl-tab { flex: 1; background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text-dim); font-weight: 700; font-size: .84rem; padding: 8px; border-radius: 10px; cursor: pointer; }
.dl-tab.active { background: var(--mint); color: #06120d; border-color: var(--mint); }
.dl-panel[hidden] { display: none; }
.dl-qr { display: block; margin: 6px auto 10px; border-radius: 10px; border: 1px solid var(--border); }
.dl-fallback { font-size: .8rem; color: var(--text-dim); margin-top: 8px; }

@media (max-width: 900px) {
  #sidebar {
    position: fixed; z-index: 50; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.25);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar-scrim {
    display: block; position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.4);
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  #sidebar-scrim.open { opacity: 1; pointer-events: auto; }
  .mobile-only { display: flex; }
  .wordmark { font-size: .98rem; }
  .composer-landing { margin-top: 20px; }
  .plans-grid { grid-template-columns: 1fr 1fr; }
  .pill-btn span.pill-label-long { display: none; }
}

/* Embed mode: rendered inside the floating widget iframe on Hub and other
   Sove solution sites. Same app, same backend — just chat-only chrome. */
body.embed-mode { background: var(--bg); }
body.embed-mode #sidebar,
body.embed-mode #sidebar-scrim,
body.embed-mode #menu-btn,
body.embed-mode #download-btn,
body.embed-mode .skip-link { display: none !important; }
body.embed-mode #shell { display: block; }
body.embed-mode #main { min-height: 100vh; }
body.embed-mode .chat { height: 100vh; }
body.embed-mode #topbar { position: sticky; }
