:root {
  --bg: #fff;
  --side: #f9f9f9;
  --hover: #ececec;
  --bubble: #f4f4f4;
  --menu: #fff;
  --text: #0d0d0d;
  --muted: #8f8f8f;
  --border: #e5e5e5;
  --field: #fff;
  --btn: #0d0d0d;
  --btn-text: #fff;
  --accent: #0285ff;
  --shadow: 0 0 0 1px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
  --menu-shadow: 0 0 0 1px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121;
    --side: #181818;
    --hover: #2f2f2f;
    --bubble: #303030;
    --menu: #353535;
    --text: #ececec;
    --muted: #9b9b9b;
    --border: #3a3a3a;
    --field: #303030;
    --btn: #ececec;
    --btn-text: #0d0d0d;
    --accent: #48aaff;
    --shadow: none;
    --menu-shadow: 0 0 0 1px rgba(255,255,255,.06), 0 8px 24px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 ui-sans-serif, -apple-system, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

#loadbar {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: var(--text); z-index: 30;
  transition: width .2s, opacity .4s .2s;
}
#loadbar.done { opacity: 0; }

.icon-btn {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 8px;
  color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* sidebar */
#sidebar {
  width: 260px; flex-shrink: 0;
  background: var(--side);
  display: flex; flex-direction: column;
  padding: 8px;
  transition: margin-left .2s ease;
}
body.side-closed #sidebar { margin-left: -260px; }
.side-top { display: flex; justify-content: space-between; align-items: center; padding-left: 10px; margin-bottom: 8px; }
.wordmark { font-weight: 600; letter-spacing: -.02em; }
.side-item {
  display: flex; align-items: center; gap: 10px;
  height: 36px; padding: 0 10px; border-radius: 8px;
  font-size: 14px; text-align: left;
}
.side-item:hover { background: var(--hover); }
.side-label { font-size: 12px; color: var(--muted); padding: 16px 10px 4px; }
#chats { flex: 1; overflow-y: auto; }
.chat-item {
  display: flex; align-items: center;
  border-radius: 8px; padding: 0 4px 0 10px; height: 36px;
  font-size: 14px; cursor: pointer;
}
.chat-item span { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-item:hover, .chat-item.active { background: var(--hover); }
.chat-item .icon-btn { width: 28px; height: 28px; visibility: hidden; }
.chat-item .icon-btn svg { width: 16px; height: 16px; }
.chat-item:hover .icon-btn { visibility: visible; }
.upgrade { height: auto; padding: 8px 10px; }
.upgrade span { display: flex; flex-direction: column; line-height: 1.35; }
.upgrade small { color: var(--muted); font-size: 12px; }

/* main */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
header {
  display: flex; align-items: center; gap: 4px;
  height: 56px; padding: 0 8px; flex-shrink: 0;
}
#open-side { display: none; }
body.side-closed #open-side { display: grid; }
#share { margin-left: auto; }
#model-btn {
  display: flex; align-items: center; gap: 4px;
  height: 36px; padding: 0 8px 0 12px; border-radius: 8px;
  font-size: 18px; font-weight: 500;
}
#model-btn:hover { background: var(--hover); }
#model-btn svg { width: 16px; height: 16px; color: var(--muted); }

/* menus */
.menu-wrap { position: relative; }
.menu {
  display: none; position: absolute; top: 42px; left: 0; z-index: 20;
  min-width: 240px; padding: 6px;
  background: var(--menu); border-radius: 16px; box-shadow: var(--menu-shadow);
}
.menu.up { top: auto; bottom: 44px; }
.menu.open { display: block; }
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 8px 10px; border-radius: 10px;
  font-size: 14px; text-align: left; white-space: nowrap;
}
.menu-item:hover { background: var(--hover); }
.menu-item.on { color: var(--accent); }
.model-item { min-width: 280px; }
.model-item.on { color: inherit; }
.model-item span { flex: 1; display: flex; flex-direction: column; line-height: 1.35; }
.model-item b { font-weight: 500; }
.model-item small { color: var(--muted); font-size: 13px; }

/* messages */
#scroll { flex: 1; overflow-y: auto; }
#messages { max-width: 768px; margin: 0 auto; padding: 8px 24px 32px; }
.msg { margin: 0 0 28px; overflow-wrap: anywhere; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.bubble {
  max-width: 70%; white-space: pre-wrap;
  background: var(--bubble); border-radius: 18px; padding: 8px 18px;
}
.files { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: flex-end; gap: 6px; }
.msg.bot .text { white-space: pre-wrap; }
.text.pending::after {
  content: ""; display: inline-block; vertical-align: middle;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text); animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(.6); opacity: .5; } }

.status, .meta, .thought summary { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.shimmer {
  background: linear-gradient(90deg, var(--muted) 30%, var(--text) 50%, var(--muted) 70%) 0 0 / 300% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.thought summary { cursor: pointer; list-style: none; width: fit-content; }
.thought summary::-webkit-details-marker { display: none; }
.thought div {
  border-left: 2px solid var(--border); padding-left: 14px; margin: 0 0 14px;
  color: var(--muted); font-size: 14px; white-space: pre-wrap;
}
.memory {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted); margin-bottom: 8px;
}
.memory svg { width: 16px; height: 16px; }

.actions { display: flex; gap: 0; margin: 6px 0 0 -8px; opacity: 0; transition: opacity .15s; }
.msg.bot:hover .actions, .msg.bot:last-child .actions { opacity: 1; }
.actions .icon-btn { width: 32px; height: 32px; }
.actions svg { width: 18px; height: 18px; }
.actions .on { color: var(--text); }
.actions .on svg { fill: currentColor; fill-opacity: .15; }
.flip svg { transform: rotate(180deg); }

/* composer */
#composer-wrap { padding: 0 24px 8px; }
#hero { display: none; }
#composer {
  width: 100%; max-width: 768px; margin: 0 auto;
  display: flex; flex-direction: column;
  background: var(--field); border: 1px solid var(--border);
  border-radius: 28px; padding: 10px 10px 8px;
  box-shadow: var(--shadow);
}
#attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 2px 8px; }
#attachments:empty { display: none; }
#input {
  resize: none; border: 0; outline: 0; background: none;
  color: var(--text); font: inherit; line-height: 24px;
  padding: 4px 10px; max-height: 200px;
}
#input::placeholder { color: var(--muted); }
.toolbar { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
#pills { flex: 1; display: flex; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px 0 10px; border-radius: 16px;
  font-size: 14px; color: var(--accent);
}
.pill:hover { background: var(--hover); }
.pill svg { width: 18px; height: 18px; }
#plus, #mic { border-radius: 50%; }
#mic.on { color: #e5484d; animation: pulse 1.2s ease-in-out infinite; }
#send {
  display: grid; place-items: center; flex-shrink: 0;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--btn); color: var(--btn-text);
}
#send:disabled { opacity: .3; cursor: default; }
#send .stop { display: none; }
#send.busy .arrow { display: none; }
#send.busy .stop { display: grid; }
#send span { display: grid; }

.file-chip {
  display: inline-flex; align-items: center; gap: 8px;
  max-width: 240px; padding: 6px 4px 6px 6px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--field); font-size: 13px;
}
.msg .file-chip { padding-right: 12px; }
.file-icon {
  display: grid; place-items: center; width: 32px; height: 32px;
  border-radius: 8px; background: #ff5588; color: #fff;
}
.file-icon svg { width: 18px; height: 18px; }
.file-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.file-chip .icon-btn { width: 24px; height: 24px; }
.file-chip .icon-btn svg { width: 14px; height: 14px; }

#disclaimer { margin: 8px 0 0; text-align: center; font-size: 12px; color: var(--muted); }

#main.empty #scroll, #main.empty #disclaimer { display: none; }
#main.empty #composer-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; padding-bottom: 18vh; }
#main.empty #hero {
  display: block; text-align: center;
  font-size: 28px; font-weight: 400; margin: 0 0 28px;
}

/* plans */
#plans {
  display: none; position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.5); padding: 16px;
  place-items: center; overflow-y: auto;
}
#plans.open { display: grid; }
.plans-card {
  position: relative; width: 100%; max-width: 920px;
  background: var(--bg); border-radius: 20px; padding: 32px;
}
.plans-card h2 { margin: 0 0 24px; text-align: center; font-size: 24px; font-weight: 500; }
.plans-card .close { position: absolute; top: 16px; right: 16px; }
.plans-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.plan { border: 1px solid var(--border); border-radius: 16px; padding: 24px; }
.plan.featured { background: var(--side); border-color: var(--accent); }
.plan h3 { margin: 0 0 8px; font-size: 20px; font-weight: 500; }
.price { font-size: 32px; font-weight: 600; margin-bottom: 16px; }
.price small { font-size: 13px; font-weight: 400; color: var(--muted); }
.plan-btn {
  width: 100%; height: 40px; border-radius: 20px;
  background: var(--btn); color: var(--btn-text); font-size: 14px; font-weight: 500;
}
.plan-btn:disabled { background: none; border: 1px solid var(--border); color: var(--muted); cursor: default; }
.plan ul { margin: 20px 0 0; padding-left: 20px; font-size: 14px; line-height: 2; }

#scrim { display: none; }
@media (max-width: 767px) {
  #sidebar { position: fixed; inset: 0 auto 0 0; z-index: 5; }
  body.side-closed #scrim { display: none; }
  #scrim { display: block; position: fixed; inset: 0; z-index: 4; background: rgba(0,0,0,.4); }
  #messages { padding: 8px 16px 24px; }
  #composer-wrap { padding: 0 12px 8px; }
  .bubble { max-width: 85%; }
  .chat-item .icon-btn { visibility: visible; }
  .actions { opacity: 1; }
  .plans-grid { grid-template-columns: 1fr; }
  .plans-card { padding: 24px 16px; }
}

.img-chip { position: relative; }
.img-chip img { display: block; width: 56px; height: 56px; object-fit: cover; border-radius: 12px; }
.img-chip .icon-btn {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--btn); color: var(--btn-text);
}
.img-chip .icon-btn svg { width: 12px; height: 12px; }
.msg .img-chip img { width: auto; height: auto; max-width: min(280px, 70vw); max-height: 280px; border-radius: 18px; }
