:root {
  --bg: #f6f7f5; --panel: #eceeea; --card: #ffffff; --text: #1c211d; --muted: #667067;
  --line: #dde1da; --accent: #1f6f54; --accent-text: #ffffff; --user: #e2efe8; --code: #f0f2ee;
  --danger: #a8341f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121513; --panel: #181c19; --card: #1d221f; --text: #e6eae6; --muted: #929c94;
    --line: #2c332e; --accent: #5cc39b; --accent-text: #0c1a13; --user: #1f3128; --code: #0d100e;
    --danger: #ef8d78;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; background: var(--bg); color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea, .button { font: inherit; color: inherit; }
button, .button, select { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 10px;
  padding: 8px 16px; font-weight: 600;
}
.primary:disabled { opacity: .45; cursor: default; }
.ghost, select {
  background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px;
}
.ghost:hover, select:hover { border-color: var(--muted); }

#side {
  width: 264px; flex: none; display: flex; flex-direction: column; gap: 10px;
  padding: 14px; background: var(--panel); border-right: 1px solid var(--line);
}
#search { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 6px 10px; }
#list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.item { display: flex; align-items: center; border-radius: 9px; }
.item:hover, .item.active { background: var(--card); }
.item button { background: none; border: 0; padding: 7px 10px; }
.item .name { flex: 1; text-align: left; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.item .del { visibility: hidden; color: var(--muted); }
.item:hover .del, .item .del:focus-visible, .item .del.sure { visibility: visible; }
.item .del.sure { color: var(--danger); font-weight: 600; }
.item.busy .name::before { content: "● "; color: var(--accent); }
#folder, #logout { font-size: 13px; }
#files { max-height: 32vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; font-size: 13px; overflow-wrap: anywhere; }
#files a { color: var(--accent); }
.login { margin: auto; width: min(340px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 12px; }
.login h1 { font-size: 24px; text-align: center; }
.login input { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 12px; }
.login .primary { padding: 10px; }
.login p { margin: 0; min-height: 1.6em; text-align: center; }

main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
h1 { font-size: 15px; margin: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#menu { display: none; }
#banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: 14px auto 0; width: min(780px, calc(100% - 32px)); padding: 12px 16px;
  background: var(--card); border: 1px solid var(--accent); border-radius: 12px;
}
#scroll { flex: 1; overflow-y: auto; }
#thread { max-width: 780px; margin: 0 auto; padding: 24px 16px; display: flex; flex-direction: column; gap: 22px; }
.empty { text-align: center; color: var(--muted); margin-top: 16vh; }
.empty strong { display: block; color: var(--text); font-size: 26px; margin-bottom: 6px; }

.msg { min-width: 0; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; max-width: 85%; background: var(--user); padding: 10px 14px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; }
.attached { font-size: 13px; color: var(--muted); }
.outputs { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.outputs a {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; max-width: 460px;
  padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); text-decoration: none;
}
.outputs a:hover { border-color: var(--accent); }
.outputs strong { color: var(--accent); flex: none; font-size: 13px; }
.tools { color: var(--muted); font-size: 13px; border-left: 2px solid var(--line); padding-left: 10px; margin-bottom: 10px; }
.note { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); white-space: pre-wrap; }
.typing { color: var(--muted); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .typing { animation: none; } }

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md table, .md .pre { margin: 0 0 12px; }
.md h2, .md h3, .md h4 { margin: 20px 0 8px; line-height: 1.3; }
.md h2 { font-size: 20px; } .md h3 { font-size: 17px; } .md h4 { font-size: 15px; }
.md a { color: var(--accent); }
.md code { background: var(--code); border-radius: 5px; padding: 1px 5px; font: 13px ui-monospace, Menlo, monospace; }
.md blockquote { border-left: 3px solid var(--line); padding-left: 12px; color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); }
.pre { background: var(--code); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.pre .head { display: flex; justify-content: space-between; padding: 4px 8px 4px 14px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.pre .head button { background: none; border: 0; font-size: 12px; color: var(--muted); }
.pre pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.pre pre code { background: none; padding: 0; white-space: pre; overflow-wrap: normal; }
.table { overflow-x: auto; }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; overflow-wrap: normal; }

#composer {
  width: min(780px, calc(100% - 32px)); margin: 0 auto 6px; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px;
}
#usage {
  width: min(780px, calc(100% - 32px)); margin: 0 auto 8px; padding: 0 4px; background: none; border: 0;
  color: var(--muted); font-size: 12px; line-height: 1.5; text-align: center;
}
#usage .low { color: var(--danger); font-weight: 600; }
#composer:focus-within, #composer.drag { border-color: var(--accent); }
#input { width: 100%; border: 0; outline: 0; resize: none; background: none; max-height: 220px; padding: 4px 2px; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; }
.spacer { flex: 1; }
#chips { display: flex; flex-wrap: wrap; gap: 6px; }
#chips button { font-size: 13px; background: var(--user); border: 0; border-radius: 8px; padding: 3px 10px; margin-bottom: 6px; }

@media (max-width: 760px) {
  #menu { display: block; }
  #side { position: fixed; inset: 0 auto 0 0; z-index: 2; transform: translateX(-100%); }
  #side.open { transform: none; box-shadow: 0 0 40px #0006; }
  .item .del { visibility: visible; }
}
