:root {
  --bg: #f5f5f7;
  color-scheme: light;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --border: #d2d2d7;
  --muted: #e8e8ed;
  --bubble: #e8e8ed;
  --pill: #e8e8ed;
  --pill-active: #e8f2ff;
  --accent: #0071e3;
  --imessage-blue: #0071e3;
  --error: #c2362b;
  --ok: #2f7d4f;
  --col: 720px;
  --topbar-h: 68px;
  --tabbar-h: 64px;
  --tabbar-gap: 16px;
  --composer-h: 60px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }
a { color: inherit; }
button { font: inherit; color: inherit; }

svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

h1 {
  font-family: "Newsreader", Georgia, serif;
  font-size: 1.9rem;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.6px;
}

h2 { font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; }

.muted { color: var(--text-2); }
.hint { font-size: 0.8125rem; color: var(--text-2); margin-top: -6px; }

.loading { position: fixed; inset: 0; display: grid; place-items: center; }
.loading img { width: 72px; opacity: 0.5; animation: pulse 1.2s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: 0.15; } }
.loading-note {
  position: absolute; left: 24px; right: 24px; top: calc(50% + 64px);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center; font-size: 0.9375rem; line-height: 1.45; color: var(--text-2);
}
.loading-note button {
  height: 40px; padding: 0 20px; border: 0; border-radius: 999px;
  background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}

/* ---------- Shell ---------- */

.shell { position: relative; height: 100vh; height: 100dvh; overflow: hidden; }
.main { height: 100%; display: flex; }
.view { flex: 1; min-width: 0; }

/* ---------- Floating top bar ---------- */

.topbar {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 20px;
  background: linear-gradient(rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.4) 55%, rgba(255, 255, 255, 0));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar.feed { background: none; }

/* Christian's avatar + name, centered in the top bar on the Chat tab only. */
.agent {
  position: absolute;
  left: 50%;
  top: calc(14px + env(safe-area-inset-top));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: var(--text);
}
.agent-avatar {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(16, 17, 19, 0.08);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.agent-avatar img { width: 40px; height: auto; }
.agent-name {
  margin-top: -8px;
  padding: 4px 13px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(16, 17, 19, 0.06);
  font-size: 0.875rem;
  font-weight: 600;
  position: relative;
}
.topbar:not(.bare) { padding-bottom: 28px; }
.topbar > #menu-btn { margin-right: auto; }

.round-btn {
  justify-self: start;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(16, 17, 19, 0.06);
  color: var(--text);
}
.round-btn svg { width: 22px; height: 22px; stroke-width: 2; }

.pill-btn {
  justify-self: end;
  height: 48px;
  padding: 0 20px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(16, 17, 19, 0.06);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- Floating tab bar ---------- */

.tabbar {
  --tabs: 5; /* Chat · Goals · Groups · Feed · Library (4 when the groups flag is off, set from JS) */
  position: absolute;
  left: 50%;
  bottom: calc(var(--tabbar-gap) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 5;
  width: min(420px, calc(100% - 32px));
  height: var(--tabbar-h);
  padding: 6px;
  display: flex;
  gap: 4px;
  border-radius: 999px;
  background: rgba(244, 244, 245, 0.78);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  backdrop-filter: blur(20px) saturate(1.6);
  border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(16, 17, 19, 0.08);
}

.tabbar a {
  flex: 1;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.tabbar a:hover { color: var(--text); }
.tabbar a { position: relative; z-index: 1; }
.tabbar a[aria-current="page"] { color: var(--text); }

/* One highlight pill that slides between tabs. --tab is set from JS (0 to --tabs - 1); tabs are 4px apart. */
.tab-indicator {
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 6px;
  width: calc((100% - 12px - (var(--tabs) - 1) * 4px) / var(--tabs));
  border-radius: 999px;
  background: var(--pill-active);
  transform: translateX(calc(var(--tab, 0) * (100% + 4px)));
  transition: transform 0.38s cubic-bezier(0.3, 0.8, 0.25, 1), opacity 0.2s;
}
.tab-indicator.off { opacity: 0; }
.tabbar svg { width: 26px; height: 26px; }

/* ---------- Pages ---------- */

.view-page {
  overflow-y: auto;
  padding: calc(var(--topbar-h) + 16px + env(safe-area-inset-top)) 20px calc(var(--tabbar-h) + var(--tabbar-gap) + 40px + env(safe-area-inset-bottom));
}
.view-page > * { max-width: var(--col); margin-left: auto; margin-right: auto; }
.page-head { margin-bottom: 28px; }
.page-head p { margin-top: 8px; line-height: 1.55; }

.me-head { display: flex; align-items: center; gap: 16px; }
.me-head p { margin-top: 4px; }

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  font-weight: 600;
  flex: none;
}

.block { padding: 24px 0; border-top: 1px solid var(--border); }
.block > h2 { margin-bottom: 14px; }
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

.list { display: flex; flex-direction: column; }

.item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--muted);
}
.item:last-child { border-bottom: 0; }
.item-body { flex: 1; min-width: 0; }
.item-title { font-weight: 500; line-height: 1.4; overflow-wrap: anywhere; }
.item-meta { margin-top: 3px; font-size: 0.8125rem; color: var(--text-2); overflow-wrap: anywhere; }
.item-actions { display: flex; gap: 12px; flex: none; }

.empty { padding: 14px 0; color: var(--text-3); font-size: 0.9rem; line-height: 1.5; }

.tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--muted);
  color: var(--text-2);
  margin-right: 6px;
  vertical-align: 1px;
}
.tag-ok { background: #e7f3ec; color: var(--ok); }

/* ---------- Forms ---------- */

.field {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font: inherit;
  color: var(--text);
  background: #fff;
  outline: 0;
  transition: border-color 0.15s;
}
.field:focus { border-color: var(--text-2); }
.field:disabled { background: var(--muted); color: var(--text-2); }
textarea.field { resize: vertical; line-height: 1.45; }

.field-label { display: flex; flex-direction: column; gap: 6px; font-size: 0.8125rem; font-weight: 500; color: var(--text-2); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.inline-form { display: flex; flex-direction: column; gap: 10px; padding: 4px 0 16px; }
.settings { display: flex; flex-direction: column; gap: 14px; }
.settings h2:not(:first-child) { margin-top: 14px; }

.form-actions { display: flex; align-items: center; gap: 14px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  white-space: nowrap;
}
.btn:hover { opacity: 0.86; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-small { height: 36px; padding: 0 16px; font-size: 0.875rem; }
.btn-ghost { background: #fff; color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.btn-danger { background: var(--error); }

.btn-link {
  background: none;
  border: 0;
  padding: 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
}
.btn-link:hover { color: var(--text); }
.btn-link.danger-text:hover { color: var(--error); }

.toggle { display: flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 500; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle span {
  width: 42px;
  height: 26px;
  border-radius: 999px;
  background: #d9d9dd;
  position: relative;
  flex: none;
  transition: background 0.15s;
}
.toggle span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform 0.15s;
}
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(16px); }
.toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.consent {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 20px;
  margin-bottom: 8px;
  border-radius: 22px;
  background: var(--bubble);
}
.consent p { margin-top: 4px; font-size: 0.875rem; line-height: 1.5; }

.data-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.danger h2 { color: var(--error); }
.danger .inline-form { margin-top: 12px; max-width: 360px; }

.legal-links { display: flex; gap: 20px; padding-top: 24px; font-size: 0.8125rem; color: var(--text-2); }

/* ---------- Connection cards ---------- */

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  border-radius: 24px;
  background: var(--bubble);
}
.card-top { display: flex; align-items: center; gap: 12px; }
.card-icon { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 18px; background: #fff; }
.card-name { font-weight: 600; }
.card-desc { font-size: 0.875rem; line-height: 1.5; color: var(--text-2); flex: 1; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-foot .muted { font-size: 0.8125rem; }
.card .tag { background: #fff; }
.card .tag-ok { background: #e7f3ec; }
