:root {
  --bg: #000000; --bg-side: #050505; --bg-elev: #111111; --bg-hover: #181818; --bg-active: #202020;
  --text: #ececec; --muted: #b4b4b4; --faint: #8e8e8e; --line: rgba(255,255,255,.1);
  --btn: #ececec; --btn-text: #0d0d0d; --danger: #ef4444; --code-bg: #050505; --code-head: #111111;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.6; overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea, select { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }
[hidden] { display: none !important; }

#app { display: flex; height: 100vh; height: 100dvh; width: 100%; position: relative; }

#sidebar { width: 260px; flex: none; background: var(--bg-side); display: flex; flex-direction: column; padding: 8px; transition: margin-left .2s ease, transform .2s ease; z-index: 30; }
.sb-top { display: flex; justify-content: space-between; align-items: center; height: 44px; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.sb-new { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; font-size: 14px; margin-top: 2px; }
.sb-new:hover { background: var(--bg-hover); }
.sb-search { display: flex; align-items: center; gap: 10px; padding: 0 10px; margin: 2px 0 6px; border-radius: 10px; color: var(--muted); }
.sb-search:focus-within { background: var(--bg-hover); }
.sb-search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; font-size: 14px; padding: 9px 0; }
.sb-search input::placeholder { color: var(--muted); }
.sb-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.sb-group { font-size: 12px; font-weight: 600; color: var(--faint); padding: 14px 10px 6px; }
.sb-item { position: relative; display: flex; align-items: center; border-radius: 10px; }
.sb-item:hover, .sb-item.menu-open { background: var(--bg-hover); }
.sb-item.active { background: var(--bg-active); }
.sb-item .t { flex: 1; min-width: 0; text-align: left; padding: 9px 10px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; mask-image: linear-gradient(to right, #000 85%, transparent); -webkit-mask-image: linear-gradient(to right, #000 85%, transparent); }
.sb-item .more { width: 32px; height: 32px; margin-right: 4px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); opacity: 0; }
.sb-item:hover .more, .sb-item.active .more, .sb-item.menu-open .more { opacity: 1; }
@media (hover: none) { .sb-item .more { opacity: 1; } }
.sb-empty { font-size: 13px; color: var(--faint); padding: 14px 10px; }
.sb-foot { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; margin-top: 4px; text-align: left; }
.sb-foot:hover { background: var(--bg-hover); }
.sb-foot-name { flex: 1; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-foot-i { color: var(--muted); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--btn); color: var(--btn-text); display: grid; place-items: center; font-size: 13px; font-weight: 600; flex: none; }
#backdrop { display: none; }
body.sb-collapsed #sidebar { margin-left: -260px; }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.topbar { display: flex; align-items: center; justify-content: space-between; height: 52px; padding: 0 8px; flex: none; }
.brand { font-size: 18px; font-weight: 600; padding: 0 8px; }
#sbOpen, #topNew { visibility: hidden; }
body.sb-collapsed #sbOpen, body.sb-collapsed #topNew { visibility: visible; }
#scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: auto; }
.empty { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 20px 120px; text-align: center; }
.empty h1 { font-size: 28px; font-weight: 600; margin: 0 0 22px; line-height: 1.3; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 640px; }
.chip { border: 1px solid var(--line); border-radius: 18px; padding: 8px 14px; font-size: 14px; color: var(--muted); }
.chip:hover { background: var(--bg-hover); color: var(--text); }
body.has-chat .empty { display: none; }
.thread { max-width: 768px; margin: 0 auto; padding: 8px 16px 24px; }
body:not(.has-chat) .thread { display: none; }

.msg { display: flex; margin: 14px 0; }
@keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--bg-elev); border-radius: 22px; padding: 9px 18px; max-width: 80%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.bot { flex-direction: column; align-items: flex-start; margin: 6px 0; }
.msg.bot.first { margin-top: 18px; }
.msg.bot .content { width: 100%; overflow-wrap: anywhere; }
.content p { margin: 0 0 .8em; } .content p:last-child { margin-bottom: 0; }
.content h1, .content h2, .content h3, .content h4 { margin: 1em 0 .4em; line-height: 1.3; font-size: 1.1em; }
.content ul, .content ol { margin: .4em 0 .8em; padding-left: 1.5em; }
.content li { margin: .2em 0; }
.content blockquote { margin: .6em 0; padding-left: 14px; border-left: 3px solid var(--line); color: var(--muted); }
.content a { color: inherit; text-decoration: underline; text-underline-offset: 3px; }
.content code.inl { font-family: var(--mono); font-size: .88em; background: var(--bg-elev); border-radius: 6px; padding: .15em .4em; }
.code { margin: .8em 0; border-radius: 12px; overflow: hidden; background: var(--code-bg); border: 1px solid var(--line); }
.code-h { display: flex; justify-content: space-between; align-items: center; background: var(--code-head); padding: 6px 12px; font-size: 12px; color: var(--muted); }
.code-h button { font-size: 12px; color: var(--muted); padding: 4px 6px; border-radius: 6px; }
.code-h button:hover { color: var(--text); }
.code pre { margin: 0; padding: 14px 16px; overflow-x: auto; font-family: var(--mono); font-size: 13.5px; line-height: 1.55; }
.actions { display: flex; gap: 2px; margin: 4px 0 0 -8px; opacity: 0; transition: opacity .15s; }
.msg.bot:hover .actions, .msg.bot.last-of-turn .actions { opacity: 1; }
@media (hover: none) { .actions { opacity: 1; } }
.actions .icon-btn { width: 32px; height: 32px; }
.actions .icon-btn svg { width: 17px; height: 17px; }

.typing { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--text); margin: 8px 4px; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(.7); opacity: .5; } 50% { transform: scale(1.05); opacity: 1; } }
.err { color: var(--muted); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 14px; display: flex; gap: 12px; align-items: center; justify-content: space-between; width: 100%; }
.err button { border: 1px solid var(--line); border-radius: 18px; padding: 6px 14px; color: var(--text); flex: none; }
.err button:hover { background: var(--bg-hover); }

.jump { position: absolute; left: 50%; bottom: 118px; transform: translateX(-50%); width: 36px; height: 36px; border-radius: 50%; background: var(--bg); border: 1px solid var(--line); display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.25); z-index: 5; }
.jump svg { width: 18px; height: 18px; }

.composer-wrap { flex: none; max-width: 768px; width: 100%; margin: 0 auto; padding: 0 16px calc(8px + env(safe-area-inset-bottom)); }
.composer { display: flex; align-items: flex-end; gap: 8px; background: #303030; border-radius: 26px; padding: 8px 8px 8px 20px; }
.composer textarea { flex: 1; min-width: 0; resize: none; background: none; border: 0; outline: 0; max-height: 200px; padding: 8px 0; line-height: 1.5; }
.composer textarea::placeholder { color: var(--faint); }
.send { width: 36px; height: 36px; border-radius: 50%; background: var(--btn); color: var(--btn-text); display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .25; cursor: default; }
.send svg { width: 19px; height: 19px; stroke-width: 2.4; }
.send.stop svg { fill: currentColor; stroke: none; width: 14px; height: 14px; }
.fine { margin: 8px 0 0; text-align: center; font-size: 12px; color: var(--faint); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal-card { background: var(--bg); border: 1px solid var(--line); border-radius: 20px; width: 100%; max-width: 520px; max-height: 88vh; max-height: 88dvh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 14px 6px 22px; }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.modal-body { padding: 8px 22px 12px; overflow-y: auto; font-size: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 22px 18px; }
.btn { border-radius: 20px; padding: 9px 18px; font-size: 14px; border: 1px solid var(--line); }
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--btn); color: var(--btn-text); border-color: transparent; }
.btn.primary:hover { opacity: .85; background: var(--btn); }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.danger:hover { background: var(--danger); opacity: .85; }
.set-sec { margin: 6px 0 18px; }
.set-sec h3 { font-size: 13px; font-weight: 600; color: var(--faint); margin: 0 0 8px; }
.field { display: block; margin: 0 0 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field textarea, .field select { width: 100%; background: var(--bg-elev); border: 1px solid transparent; border-radius: 12px; padding: 10px 12px; outline: 0; font-size: 14px; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--line); }
.field textarea { min-height: 84px; resize: none; }
.hint { font-size: 12px; color: var(--faint); margin: 4px 0 0; line-height: 1.5; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }

.settings-page { position: fixed; inset: 0; z-index: 90; background: var(--bg); display: flex; overflow: auto; }
.settings-shell { display: flex; flex-direction: column; width: 100%; min-height: 100%; max-width: 920px; margin: 0 auto; }
.settings-header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 14px; min-height: 76px; padding: 10px 24px; background: var(--bg); border-bottom: 1px solid var(--line); }
.settings-heading { flex: 1; min-width: 0; }
.settings-heading > span { display: block; color: var(--faint); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; line-height: 1.2; }
.settings-heading h1 { margin: 2px 0 0; font-size: 21px; line-height: 1.3; font-weight: 650; }
.settings-save-top { flex: none; }
.settings-content { flex: 1; width: 100%; max-width: 680px; margin: 0 auto; padding: 28px 24px 36px; }
.settings-content .set-sec { margin: 0 0 30px; }
.settings-content .set-sec h3 { font-size: 13px; margin-bottom: 14px; }
.settings-content .field { margin-bottom: 18px; }
.settings-content .field > span { margin-bottom: 7px; }
.settings-content .field textarea { min-height: 112px; }
.settings-data-actions { flex-direction: column; align-items: stretch; }
.settings-data-actions .btn { width: 100%; min-height: 44px; text-align: left; border-radius: 12px; padding: 10px 14px; }
.settings-footer { position: sticky; bottom: 0; padding: 14px 24px calc(14px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); display: flex; justify-content: center; }
.settings-footer .btn { width: min(100%, 632px); min-height: 46px; border-radius: 14px; }

.menu { position: fixed; z-index: 70; background: var(--bg-elev); border: 1px solid var(--line); border-radius: 14px; padding: 6px; min-width: 170px; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 8px; font-size: 14px; text-align: left; }
.menu button:hover { background: var(--bg-hover); }
.menu button.danger { color: var(--danger); }
.menu svg { width: 17px; height: 17px; }
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--btn); color: var(--btn-text); border-radius: 20px; padding: 9px 18px; font-size: 14px; z-index: 120; max-width: 90vw; }

@media (max-width: 800px) {
  #sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; max-width: 86vw; margin-left: 0 !important; transform: translateX(-100%); }
  body.sb-open #sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  body.sb-open #backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 25; }
  #sbOpen, #topNew { visibility: visible !important; }
  .empty h1 { font-size: 24px; }
  .msg.user .bubble { max-width: 88%; }
  .jump { bottom: 112px; }
}

@media (max-width: 600px) {
  .settings-header { min-height: 66px; gap: 8px; padding: 8px 12px; }
  .settings-heading h1 { font-size: 19px; }
  .settings-content { padding: 24px 18px 28px; }
  .settings-footer { padding-left: 18px; padding-right: 18px; }
}


@keyframes olma-fade-up {
  from { opacity: 0; transform: translateY(12px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes olma-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes olma-slide-in {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes olma-soft-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
  50% { box-shadow: 0 0 0 4px rgba(255,255,255,.045); }
}


.msg { animation: olma-fade-up .28s cubic-bezier(.2,.75,.25,1) both; }
.msg.user .bubble { transition: background .2s ease, transform .2s ease; }
.msg.user .bubble:hover { transform: translateY(-1px); }
.msg.bot .content { animation: olma-fade-in .32s ease both; }


.icon-btn, .sb-new, .sb-foot, .sb-item, .chip, .btn, .send, .jump, .menu button {
  transition: background-color .18s ease, color .18s ease, border-color .18s ease,
              opacity .18s ease, transform .18s ease, box-shadow .18s ease;
}
.icon-btn:active, .sb-new:active, .sb-foot:active, .chip:active, .btn:active,
.menu button:active, .jump:active { transform: scale(.96); }
.send:not(:disabled):hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(255,255,255,.12); }
.send:not(:disabled):active { transform: scale(.92); }


.composer { transition: background-color .2s ease, box-shadow .2s ease, transform .2s ease; }
.composer:focus-within { background: #343434; box-shadow: 0 0 0 1px rgba(255,255,255,.10); }
.composer textarea { transition: height .15s ease; }


#sidebar { transition: margin-left .24s cubic-bezier(.2,.75,.25,1), transform .24s cubic-bezier(.2,.75,.25,1); }
.sb-item { animation: olma-fade-in .22s ease both; }
.settings-page { animation: olma-fade-in .2s ease both; }
.settings-shell { animation: olma-fade-up .28s cubic-bezier(.2,.75,.25,1) both; }
.settings-content .set-sec { animation: olma-fade-up .32s ease both; }
.settings-content .set-sec:nth-child(2) { animation-delay: .035s; }
.settings-content .set-sec:nth-child(3) { animation-delay: .07s; }
.settings-content .set-sec:nth-child(4) { animation-delay: .105s; }
.settings-content .set-sec:nth-child(5) { animation-delay: .14s; }
.modal { animation: olma-fade-in .16s ease both; }
.modal-card { animation: olma-fade-up .22s cubic-bezier(.2,.75,.25,1) both; }
.menu { animation: olma-fade-up .14s ease both; transform-origin: top left; }
.toast { animation: olma-fade-up .2s ease both; }


.typing { animation: pulse 1s ease-in-out infinite, olma-soft-pulse 1.4s ease-in-out infinite; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}






* { scrollbar-width: thin; scrollbar-color: #2e2e2e transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb { background: #2e2e2e; border-radius: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
input, textarea, button { -webkit-appearance: none; appearance: none; border-radius: 0; }
input, textarea { caret-color: #e07a52; }
input::-webkit-search-cancel-button, input::-webkit-search-decoration { display: none; -webkit-appearance: none; }
input:-webkit-autofill { -webkit-text-fill-color: var(--text); -webkit-box-shadow: 0 0 0 40px var(--bg-elev) inset; }
:focus { outline: none; }
:focus-visible { outline: 2px solid rgba(224,122,82,.7); outline-offset: 2px; }
.composer textarea:focus-visible, .field input:focus-visible, .field textarea:focus-visible, .sb-search input:focus-visible { outline: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.content, .bubble, textarea, input, .code pre { -webkit-user-select: text; user-select: text; }
.icon-btn, .chip, .btn, .send, .jump, .menu button, .sb-new, .sb-foot, .sb-item .t, .sb-item .more { border-radius: 10px; }
.send { border-radius: 50%; }
.chip { border-radius: 18px; }
.btn { border-radius: 20px; }

.empty { padding: 24px 20px 120px; }
.empty h1 { font-family: Georgia, "Iowan Old Style", "Times New Roman", serif; font-weight: 400; font-size: 32px; letter-spacing: -.01em; margin: 0 0 24px; }
.empty-composer { display: none; }
@media (max-width: 800px) { .empty h1 { font-size: 27px; } .empty { padding-bottom: 110px; } }

.field input, .field textarea { -webkit-appearance: none; appearance: none; }
.f-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 7px; }
.picker { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left; background: var(--bg-elev); border: 1px solid transparent; border-radius: 12px; padding: 11px 12px 11px 14px; font-size: 14px; }
.picker:hover { background: var(--bg-hover); }
.picker svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.switch-row { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 16px; text-align: left; padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg-elev); margin-bottom: 14px; }
.sw-text { display: grid; gap: 5px; min-width: 0; }
.sw-text strong { font-size: 14px; font-weight: 600; }
.sw-text small { color: var(--muted); font-size: 12.5px; line-height: 1.55; }
.sw-track { flex: none; width: 46px; height: 28px; border-radius: 14px; background: #3a3a3a; position: relative; transition: background-color .22s ease; }
.sw-thumb { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #f2f2f2; transition: transform .24s cubic-bezier(.3,1.3,.5,1); }
.switch-row.on .sw-track { background: #e07a52; }
.switch-row.on .sw-thumb { transform: translateX(18px); }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--bg-elev); }
.seg-btn { flex: 1; padding: 9px 4px; border-radius: 10px; font-size: 13.5px; color: var(--muted); transition: background-color .18s ease, color .18s ease; }
.seg-btn.on { background: #2b2b2b; color: var(--text); }

.sheet { position: fixed; inset: 0; z-index: 110; display: flex; align-items: flex-end; justify-content: center; background: rgba(0,0,0,0); transition: background-color .2s ease; }
.sheet.show { background: rgba(0,0,0,.6); }
.sheet-card { width: 100%; max-width: 520px; max-height: 76dvh; display: flex; flex-direction: column; background: #161616; border: 1px solid var(--line); border-bottom: 0; border-radius: 22px 22px 0 0; transform: translateY(100%); transition: transform .26s cubic-bezier(.2,.8,.25,1); padding-bottom: env(safe-area-inset-bottom); }
.sheet.show .sheet-card { transform: none; }
.sheet-grab { width: 38px; height: 4px; border-radius: 2px; background: #3a3a3a; margin: 10px auto 2px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px 6px 20px; }
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.sheet-list { overflow-y: auto; padding: 4px 8px 12px; }
.sheet-item { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 12px; border-radius: 12px; font-size: 15px; text-align: left; color: var(--muted); }
.sheet-item:hover { background: var(--bg-hover); color: var(--text); }
.sheet-item.on { color: var(--text); }
.sheet-item svg { width: 19px; height: 19px; color: #e07a52; flex: none; }
@media (min-width: 801px) { .sheet { align-items: center; } .sheet-card { border-bottom: 1px solid var(--line); border-radius: 22px; transform: translateY(14px) scale(.98); opacity: 0; transition: transform .22s ease, opacity .22s ease; } .sheet.show .sheet-card { transform: none; opacity: 1; } .sheet-grab { display: none; } }
