:root {
  --ink: #17142B;
  --muted: #4E4A66;
  --ground: #F4F1FF;
  --card: #FFFFFF;
  --violet: #5534F0;
  --violet-dark: #3F22CC;
  --sun: #FFD23F;
  --mint: #2BD9A0;
  --lilac: #E4DFF7;
  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  --body: 'DM Sans', system-ui, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--violet-dark); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100%;
  padding: calc(20px + var(--safe-top)) 18px calc(110px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.app.no-tabs { padding-bottom: calc(24px + var(--safe-bottom)); }
.loading { color: var(--muted); text-align: center; margin-top: 40vh; }

/* ---------- Type ---------- */
h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: 34px;
  letter-spacing: -1px;
  line-height: 1.05;
}
h2 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 20px; }
.dot { color: var(--violet); }
.sub { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 14px 18px;
  border: 2px solid var(--ink); border-radius: 18px;
  background: var(--violet); color: #fff;
  font-weight: 700; font-size: 17px; text-decoration: none;
  box-shadow: 4px 4px 0 var(--ink);
}
.btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.btn.dark { background: var(--ink); box-shadow: 4px 4px 0 var(--sun); }
.btn.sun { background: var(--sun); color: var(--ink); }
.btn.small { min-height: 44px; padding: 9px 15px; font-size: 15px; border-radius: 999px; box-shadow: 3px 3px 0 var(--ink); }
.btn[disabled] { background: var(--lilac); color: var(--muted); box-shadow: none; cursor: default; }
.link-btn {
  border: none; background: transparent; color: var(--muted);
  font-weight: 700; font-size: 14px; min-height: 44px;
}
.back {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 40px; padding: 6px 12px 6px 8px;
  border: 2px solid var(--ink); border-radius: 999px;
  background: #fff; color: var(--ink);
  font-weight: 700; font-size: 14px; text-decoration: none;
}
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ---------- Cards ---------- */
.card {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 22px;
  padding: 16px;
  color: var(--ink);
  text-decoration: none;
}
a.card:active { transform: translate(1px, 1px); }
.plan-title { font-family: var(--display); font-weight: 800; font-size: 21px; letter-spacing: -0.4px; line-height: 1.15; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700;
  border-radius: 999px; padding: 4px 10px;
  background: var(--lilac); white-space: nowrap;
}
.pill.sun { background: var(--sun); }
.pill.mint { background: var(--mint); }
.pill.ink { background: var(--ink); color: #fff; }
.where { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 500; color: var(--muted); }
.where svg { width: 16px; height: 16px; stroke: var(--violet); }

/* ---------- Avatars ---------- */
.avatar {
  width: var(--s, 40px); height: var(--s, 40px);
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--display); font-weight: 800;
  font-size: calc(var(--s, 40px) * 0.42);
  color: var(--ink);
  border: 2px solid #fff;
}
.stack { display: flex; align-items: center; }
.stack .avatar { margin-right: -8px; }
.stack + span { margin-left: 16px; font-size: 13px; font-weight: 600; color: var(--muted); }

/* ---------- Plan detail ---------- */
.info { padding: 0; gap: 0; overflow: hidden; }
.info-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.info-row + .info-row { border-top: 2px solid #EDE9FB; }
.info-icon { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; background: #F1EDFF; color: var(--violet); }
.info-icon.sun { background: #FFF4CC; color: var(--ink); }
.member { display: flex; align-items: center; gap: 12px; background: #fff; border-radius: 16px; padding: 8px 12px; }
.member-name { font-weight: 700; flex: 1; }

/* ---------- Forms ---------- */
label { font-size: 13px; font-weight: 700; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; }
input[type="text"], input[type="email"], input[type="datetime-local"], input[type="number"], textarea {
  width: 100%;
  border: 2px solid var(--ink); border-radius: 16px;
  padding: 13px 16px; min-height: 50px;
  background: #fff; font-size: 16px;
  outline: none;
}
input:focus, textarea:focus { box-shadow: 0 0 0 3px rgba(85, 52, 240, 0.3); }
textarea { resize: vertical; min-height: 80px; }
.error { color: #B3261E; font-size: 14px; font-weight: 600; margin: 0; }

/* ---------- Chat ---------- */
/* The chat screen is pinned to the visible area (above the keyboard).
   --vvh / --vvt are set from window.visualViewport in app.js. */
body.in-chat { overflow: hidden; overscroll-behavior: none; }
.chat-screen {
  position: fixed; left: 0; right: 0; top: 0; z-index: 4;
  height: var(--vvh, 100dvh);
  transform: translateY(var(--vvt, 0px));
  display: flex; flex-direction: column;
  background: var(--ground);
}
.chat-head {
  flex-shrink: 0;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: var(--ground);
  border-bottom: 2px solid var(--ink);
  display: flex; align-items: center; gap: 10px;
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 22px;
  border: 2px solid var(--ink); background: #fff; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
  text-decoration: none; flex-shrink: 0;
}
.chat-title { flex: 1; min-width: 0; color: var(--ink); text-decoration: none; }
.chat-title strong, .chat-title span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title span { font-size: 12px; font-weight: 600; color: var(--muted); }
.msgs {
  flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px 14px;
  width: 100%; max-width: 520px; margin: 0 auto;
}
.msg { display: flex; align-items: flex-end; gap: 8px; }
.msg.mine { justify-content: flex-end; }
.msg-body { max-width: 74%; display: flex; flex-direction: column; gap: 3px; }
.msg-from { font-size: 12px; font-weight: 700; color: var(--muted); padding-left: 4px; }
.bubble {
  padding: 10px 14px; font-size: 15px; line-height: 1.4;
  background: #fff; border: 2px solid var(--ink);
  border-radius: 20px 20px 20px 6px;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.mine .bubble { background: var(--violet); color: #fff; border-radius: 20px 20px 6px 20px; }
.composer {
  flex-shrink: 0;
  background: #fff; border-top: 2px solid var(--ink);
  padding: 10px 12px calc(10px + var(--safe-bottom));
}
/* When the keyboard is open it covers the home-indicator area, so drop that padding. */
body.in-chat.keyboard-open .composer { padding-bottom: 10px; }
.composer form { max-width: 520px; margin: 0 auto; display: flex; gap: 10px; }
.composer input { border-radius: 999px; min-height: 46px; padding: 10px 16px; background: var(--ground); }
.send { width: 46px; height: 46px; border-radius: 23px; border: 2px solid var(--ink); background: var(--violet); color: #fff; display: inline-flex; align-items: center; justify-content: center; padding: 0; flex-shrink: 0; }

/* ---------- Tabs ---------- */
.tabs {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + var(--safe-bottom)); z-index: 5;
  width: min(360px, calc(100% - 32px));
  background: var(--ink); border-radius: 28px; padding: 6px;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px;
}
.tabs[hidden] { display: none; }
.tabs a {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; border-radius: 22px;
  color: #D4CFEA; font-size: 14px; font-weight: 700; text-decoration: none;
}
.tabs a.active { background: var(--sun); color: var(--ink); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 10;
  top: calc(14px + var(--safe-top)); left: 50%; transform: translateX(-50%);
  width: min(480px, calc(100% - 28px));
  background: var(--ink); color: #fff;
  border-radius: 18px; padding: 13px 16px;
  font-size: 15px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(23, 20, 43, 0.25);
}

/* ---------- Install banner ---------- */
.install {
  display: flex; align-items: center; gap: 12px;
  background: var(--sun); border: 2px solid var(--ink);
  border-radius: 18px; padding: 12px 14px; font-size: 14px; font-weight: 600;
}
.install p { margin: 0; flex: 1; line-height: 1.4; }

.empty { align-items: flex-start; padding: 22px; }
.empty h2 { font-size: 22px; }
