:root,
:root[data-theme='dark'] {
  --bg: #141416;
  --sidebar: #0d0d0f;
  --panel: #1d1d21;
  --panel-2: #26262b;
  --border: #2c2c32;
  --text: #ececf1;
  --muted: #9b9ba7;
  --user: #2a2a31;
  --accent: #ff4f8b;
  --accent-2: #a855f7;
  --grad: linear-gradient(135deg, var(--accent), var(--accent-2));
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --scrim: rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}
:root[data-theme='light'] {
  --bg: #ffffff;
  --sidebar: #f7f7f9;
  --panel: #f2f2f5;
  --panel-2: #e9e9ee;
  --border: #e3e3e9;
  --text: #17171b;
  --muted: #6b6b77;
  --user: #f1f1f5;
  --shadow: 0 10px 40px rgba(20, 20, 40, 0.15);
  --scrim: rgba(10, 10, 20, 0.35);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.app { display: flex; height: 100dvh; overflow: hidden; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 272px;
  flex: none;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  gap: 8px;
}
.sb-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -0.01em; }
.logo {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--grad); color: #fff;
  font-size: 16px; font-weight: 800; letter-spacing: 0.02em;
}
.logo.big { width: 52px; height: 52px; border-radius: 15px; font-size: 26px; margin: 0 auto 14px; }

.new-chat {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border);
  font-weight: 550;
  transition: background 0.15s;
}
.new-chat:hover { background: var(--panel); }

.sb-scroll { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.sb-label { font-size: 12px; font-weight: 600; color: var(--muted); padding: 14px 8px 6px; }
.sb-item {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 9px; text-align: left;
  position: relative; cursor: pointer;
}
.sb-item:hover, .sb-item.active { background: var(--panel); }
.sb-item.active { background: var(--panel-2); }
.sb-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.sb-name { font-weight: 550; font-size: 14px; }
.sb-sub, .sb-title { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-title { font-size: 14px; color: var(--text); flex: 1; }
.sb-item .del { opacity: 0; color: var(--muted); padding: 2px; border-radius: 6px; }
.sb-item:hover .del, .sb-item.active .del { opacity: 1; }
.sb-item .del:hover { color: var(--accent); }
.sb-empty { color: var(--muted); font-size: 13px; padding: 4px 8px; margin: 0; }

.sb-footer { border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.usage { padding: 0 6px; }
.usage-row { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.bar { height: 5px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--grad); transition: width 0.3s; }
.upgrade-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px; border-radius: 10px; font-weight: 600; color: #fff;
  background: var(--grad);
  box-shadow: 0 4px 18px rgba(255, 79, 139, 0.25);
}
.upgrade-btn svg { fill: currentColor; stroke: none; width: 16px; height: 16px; }
.upgrade-btn:hover { filter: brightness(1.08); }
.sb-link { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 9px; color: var(--muted); font-size: 14px; }
.sb-link:hover { background: var(--panel); color: var(--text); }

/* ---------- Profile menu ---------- */
.profile-wrap { position: relative; }
.profile {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 10px; text-align: left;
}
.profile:hover, .profile[aria-expanded='true'] { background: var(--panel); }
.profile-name { flex: 1; font-weight: 550; font-size: 14px; }
.profile .chev { color: var(--muted); width: 16px; height: 16px; }
.menu {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 20;
  background: var(--bg); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 6px;
  max-height: calc(100dvh - 120px); overflow-y: auto;
  animation: rise 0.12s ease-out;
}
.menu-head { font-size: 13px; color: var(--muted); padding: 8px 10px 6px; }
.menu button {
  width: 100%; display: flex; align-items: center; gap: 11px;
  padding: 8px 10px; border-radius: 8px; font-size: 14px; text-align: left;
}
.menu button:hover { background: var(--panel); }
.menu button svg { color: var(--muted); }
.menu button .chev { margin-left: auto; width: 15px; height: 15px; transition: transform 0.15s; }
.menu button[aria-expanded='true'] .chev { transform: rotate(90deg); }
.menu kbd { margin-left: auto; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 4px; }
.submenu button { padding-left: 39px; color: var(--muted); }
.submenu button:hover { color: var(--text); }
kbd {
  font: 12px/1 ui-sans-serif, system-ui, sans-serif; color: var(--muted);
  padding: 4px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel);
}

/* ---------- Avatars ---------- */
.avatar {
  --a: #ff5c9a; --b: #a855f7;
  display: grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--a), var(--b));
  color: #fff; font-weight: 700; font-size: 14px;
}
.avatar.xs { width: 22px; height: 22px; font-size: 11px; }
.avatar.sm { width: 30px; height: 30px; font-size: 13px; }
.avatar.lg { width: 60px; height: 60px; font-size: 24px; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.topbar {
  height: 56px; flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}
.top-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.tt-name { font-weight: 600; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tt-sub { font-size: 12.5px; color: var(--muted); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sm { font-weight: 650; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--panel); color: var(--text); }
.only-mobile { display: none; }

.content { flex: 1; overflow-y: auto; scroll-behavior: auto; }

/* Empty state */
.empty { max-width: 760px; margin: 0 auto; padding: 7vh 16px 24px; text-align: center; }
.empty h1 { font-size: clamp(24px, 4vw, 32px); letter-spacing: -0.02em; margin: 0 0 8px; }
.empty > p { margin: 0 auto 32px; max-width: 460px; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 36px; }
.chip {
  padding: 8px 14px; border-radius: 99px; font-size: 14px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
.chip:hover { border-color: var(--accent); background: var(--panel-2); }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.char-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.char-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 22px 14px 18px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--border);
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
}
.char-card:hover { transform: translateY(-2px); border-color: var(--accent); background: var(--panel-2); }
.cc-name { font-weight: 650; margin-top: 4px; }
.cc-tag { font-size: 13px; color: var(--muted); line-height: 1.4; }

/* Thread */
.thread { max-width: 768px; margin: 0 auto; padding: 24px 16px 32px; display: flex; flex-direction: column; gap: 22px; }
.msg { display: flex; gap: 12px; animation: rise 0.2s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
.msg.user { justify-content: flex-end; }
.msg .bubble {
  max-width: 78%; background: var(--user);
  padding: 10px 16px; border-radius: 20px 20px 6px 20px;
  overflow-wrap: anywhere;
}
.msg.bot .body { flex: 1; min-width: 0; padding-top: 3px; overflow-wrap: anywhere; }
.msg p { margin: 0 0 10px; }
.msg p:last-child { margin-bottom: 0; }
.msg em.action { color: var(--muted); }
.msg.notice {
  align-self: center; text-align: center; max-width: 560px;
  font-size: 13.5px; color: var(--muted);
  background: var(--panel); border: 1px dashed var(--border);
  padding: 8px 14px; border-radius: 12px;
}
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* Composer */
.composer-wrap { padding: 0 16px calc(12px + env(safe-area-inset-bottom)); }
.composer, .crisis, .disclaimer { max-width: 768px; margin-left: auto; margin-right: auto; }
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 24px; padding: 8px 8px 8px 18px;
  transition: border-color 0.15s;
}
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent;
  max-height: 200px; padding: 7px 0; line-height: 1.5;
}
.composer textarea::placeholder { color: var(--muted); }
.send {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--text); color: var(--bg);
  transition: opacity 0.15s;
}
.send:disabled { opacity: 0.3; cursor: default; }
.send .i-stop { display: none; fill: currentColor; stroke: none; }
.send.stop .i-send { display: none; }
.send.stop .i-stop { display: block; }
.disclaimer { text-align: center; font-size: 12px; color: var(--muted); margin-top: 8px; margin-bottom: 0; }

.crisis {
  display: flex; gap: 10px; align-items: flex-start;
  background: color-mix(in srgb, #3b82f6 14%, var(--bg));
  border: 1px solid color-mix(in srgb, #3b82f6 40%, var(--border));
  border-radius: 14px; padding: 12px 8px 12px 14px; margin-bottom: 10px;
  font-size: 14px; line-height: 1.5;
}
.crisis strong { display: block; }
.crisis .icon-btn { width: 28px; height: 28px; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 16px;
  background: var(--scrim); backdrop-filter: blur(6px);
}
.card {
  position: relative; width: 100%; max-width: 420px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 20px; padding: 28px 24px 24px;
  box-shadow: var(--shadow); text-align: center;
}
.card h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -0.01em; }
.card .close { position: absolute; top: 10px; right: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; margin: 20px 0 14px; font-size: 13px; color: var(--muted); }
input[type='date'], input[type='email'] {
  width: 100%; padding: 11px 12px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--panel); outline: 0;
}
input:focus { border-color: var(--accent); }
.check { display: flex; gap: 10px; text-align: left; font-size: 14px; align-items: flex-start; margin-bottom: 16px; }
.check input { margin-top: 4px; accent-color: var(--accent); }
.error { color: #f43f5e; font-size: 13.5px; margin: -6px 0 12px; }
.btn {
  width: 100%; padding: 11px 16px; border-radius: 11px; font-weight: 600;
  background: var(--panel-2); border: 1px solid var(--border);
}
.btn.primary { background: var(--grad); color: #fff; border: 0; }
.btn.primary:hover { filter: brightness(1.08); }
.row { display: flex; gap: 8px; margin-top: 14px; }
.row .btn { width: auto; white-space: nowrap; }
.eyebrow { margin: 0 0 4px; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.price { margin: 4px 0 14px; color: var(--muted); }
.price span { font-size: 32px; font-weight: 750; color: var(--text); letter-spacing: -0.02em; }
.perks { list-style: none; padding: 0; margin: 0 0 16px; text-align: left; display: grid; gap: 8px; }
.perks li { padding-left: 28px; position: relative; }
.perks li::before {
  content: '✓'; position: absolute; left: 0; top: 1px;
  width: 19px; height: 19px; border-radius: 50%; display: grid; place-items: center;
  font-size: 11px; font-weight: 800; color: #fff; background: var(--grad);
}

/* Login */
.login-btns { display: grid; gap: 10px; margin: 18px 0 16px; }
.btn.social { display: flex; align-items: center; justify-content: center; gap: 10px; background: var(--panel); }
.btn.social:hover { background: var(--panel-2); }
.brand-ico { width: 20px; height: 20px; stroke: none; }
#loginEmailForm { display: grid; gap: 10px; }
.fine { margin: 14px 0 0; line-height: 1.45; }
.top-login {
  padding: 7px 14px; border-radius: 99px; font-weight: 600; font-size: 14px;
  background: var(--text); color: var(--bg);
}
.top-login:hover { opacity: 0.88; }
#profileAvatar { overflow: hidden; }
#profileAvatar img { width: 100%; height: 100%; object-fit: cover; }

/* Info popups (settings, help, etc.) */
.card.left { text-align: left; max-width: 480px; max-height: calc(100dvh - 32px); overflow-y: auto; }
.card.left h2 { margin-bottom: 14px; padding-right: 32px; }
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 0; border-top: 1px solid var(--border);
}
.set-title { font-weight: 550; }
.set-sub { font-size: 13px; color: var(--muted); }
.seg { display: flex; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button { padding: 5px 12px; border-radius: 7px; font-size: 13.5px; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); font-weight: 600; }
.switch {
  position: relative; flex: none; width: 44px; height: 26px; border-radius: 99px;
  background: var(--panel-2); border: 1px solid var(--border); transition: background 0.2s;
}
.switch span {
  position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.2s;
}
.switch.on { background: var(--grad); border-color: transparent; }
.switch.on span { transform: translateX(18px); }
.btn.sm { width: auto; padding: 7px 12px; font-size: 13.5px; }
.btn.danger { color: #f43f5e; border-color: color-mix(in srgb, #f43f5e 40%, var(--border)); background: transparent; }
.btn.danger:hover { background: color-mix(in srgb, #f43f5e 12%, transparent); }
.kbd-list > div { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.usage-big { font-size: 15px; color: var(--muted); margin: 6px 0 10px; }
.usage-big span { font-size: 34px; font-weight: 750; color: var(--text); letter-spacing: -0.02em; }
.bar.big { height: 8px; margin-bottom: 10px; }
.card.left .btn { margin-top: 8px; }
.faq details { border-top: 1px solid var(--border); padding: 10px 0; }
.faq summary { cursor: pointer; font-weight: 550; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
.faq summary::after { content: '+'; color: var(--muted); font-weight: 400; }
.faq details[open] summary::after { content: '–'; }
.faq summary::-webkit-details-marker { display: none; }
.faq p { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
#feedbackForm { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
#feedbackForm textarea {
  width: 100%; resize: vertical; padding: 11px 12px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--panel); outline: 0;
}
#feedbackForm textarea:focus { border-color: var(--accent); }
.rules { padding-left: 18px; margin: 10px 0 0; display: grid; gap: 10px; }
.draft { font-size: 13px; padding: 8px 12px; border-radius: 10px; background: var(--panel); color: var(--muted); border: 1px dashed var(--border); }
.changes > div { border-top: 1px solid var(--border); padding: 12px 0; }
.changes p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.ver { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--grad); color: #fff; margin-right: 8px; }

.toast {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow);
}

/* ---------- Mobile ---------- */
.scrim { display: none; }
@media (max-width: 820px) {
  .only-mobile { display: grid; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(300px, 86vw);
    transform: translateX(-100%); transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; z-index: 30; background: var(--scrim); }
  .topbar { padding: 0 8px; }
  .msg .bubble { max-width: 88%; }
  .thread { padding-top: 16px; }
  .char-grid { grid-template-columns: 1fr 1fr; }
  .sb-item .del { opacity: 1; }
}
