* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: #F3F2EE; color: #16151F; font-family: 'Schibsted Grotesk', system-ui, sans-serif; }
a { color: #16151F; text-decoration: none; }
a:hover { color: #4A3FB8; }
::selection { background: #2E2A5C; color: #fff; }
button { font-family: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-family: 'Geist Mono', monospace; }

@keyframes msgIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes gear { to { transform: rotate(360deg); } }
@keyframes gearR { to { transform: rotate(-360deg); } }
@keyframes tread { from { background-position: 0 0; } to { background-position: 16px 0; } }
@keyframes sq { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.55); opacity: .5; } }
@keyframes led { 0%, 100% { opacity: 1; } 50% { opacity: .2; } }

.app { display: flex; height: 100vh; height: 100dvh; min-height: 520px; }

/* ---------- sidebar ---------- */
.side { flex: 0 0 264px; display: flex; flex-direction: column; border-right: 1px solid #E6E3DB; background: #EFEDE7; transition: flex-basis .3s cubic-bezier(.2,.7,.2,1); overflow: hidden; }
.side-top { padding: 14px 12px 12px 16px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; min-height: 40px; }
.logo { flex: none; width: 24px; height: 24px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; }
.logo span { border-radius: 4px; }
.logo span:nth-child(1) { background: #93AEEE; } .logo span:nth-child(2), .logo span:nth-child(3) { background: #AF92EA; } .logo span:nth-child(4) { background: #EA9C78; }
.icon-btn { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 10px; border: 1px solid transparent; background: transparent; cursor: pointer; transition: background .2s, border-color .2s; }
.icon-btn:hover { background: #FFFFFF; border-color: #D9D5CC; }
.icon-btn.bordered { border-color: #E6E3DB; border-radius: 12px; }
.new-wrap { padding: 0 12px 12px; display: flex; justify-content: center; }
.new-btn { width: 100%; min-height: 44px; border: 0; border-radius: 12px; background: #2E2A5C; color: #FFFFFF; font-size: 14px; font-weight: 500; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; transition: transform .2s, box-shadow .2s; }
.new-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(46,42,92,.3); }
.side-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.side-label { padding: 6px 16px; font-family: 'Geist Mono', monospace; font-size: 10px; letter-spacing: .1em; color: #A9A5BA; }
.chat-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; display: flex; flex-direction: column; gap: 2px; }
.chat-item { display: block; width: 100%; min-height: 48px; padding: 9px 12px; border: 0; border-radius: 10px; text-align: left; cursor: pointer; color: #16151F; background: transparent; transition: background .2s; position: relative; }
.chat-item:hover { background: #E6E3DB; }
.chat-item.on { background: #FFFFFF; box-shadow: 0 1px 0 #E2DFD7; }
.chat-item .ttl { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; padding-right: 26px; }
.chat-item .sub { display: block; margin-top: 2px; font-family: 'Geist Mono', monospace; font-size: 11px; color: #A9A5BA; }
.chat-item .del { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; opacity: 0; color: #8A86A8; border: 0; background: transparent; cursor: pointer; }
.chat-item:hover .del, .chat-item .del:focus { opacity: 1; }
.chat-item .del:hover { background: #F3F2EE; color: #16151F; }
.side-foot { padding: 12px 16px; border-top: 1px solid #E6E3DB; font-size: 12px; color: #8A86A8; line-height: 1.45; }

.side.collapsed { flex-basis: 68px; }
.side.collapsed .side-top { flex-direction: column; gap: 8px; padding: 14px 12px; }
.side.collapsed .brand-name, .side.collapsed .new-label, .side.collapsed .side-body { display: none; }
.side.collapsed .new-btn { width: 44px; }

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px clamp(16px, 3vw, 28px); border-bottom: 1px solid #E6E3DB; }
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-badge { flex: none; padding: 7px 12px; border-radius: 999px; background: #FFFFFF; border: 1px solid #E6E3DB; font-family: 'Geist Mono', monospace; font-size: 12px; color: #6E6B78; }
.scroll { flex: 1; overflow-y: auto; }
.thread { max-width: 780px; margin: 0 auto; padding: 36px 20px 24px; display: flex; flex-direction: column; gap: 30px; }
.msg { animation: msgIn .5s cubic-bezier(.2,.7,.2,1) both; }

.empty { padding: 60px 0 10px; text-align: center; }
.empty .logo { width: 52px; height: 52px; margin: 0 auto 22px; gap: 5px; }
.empty .logo span { border-radius: 6px; }
.empty h1 { margin: 0; font-size: clamp(28px, 4vw, 40px); font-weight: 500; letter-spacing: -0.03em; }
.sugg { margin-top: 24px; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chipq { min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid #E6E3DB; background: transparent; color: #6E6B78; font-size: 14px; cursor: pointer; transition: background .2s, border-color .2s, color .2s; }
.chipq:hover { background: #FFFFFF; border-color: #D9D5CC; color: #16151F; }

.user-row { display: flex; justify-content: flex-end; }
.bubble { max-width: 80%; padding: 14px 18px; border-radius: 22px 22px 6px 22px; background: #2E2A5C; color: #FFFFFF; font-size: 16px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 8px 24px rgba(46,42,92,0.18); }
.bot-row { display: flex; gap: 14px; align-items: flex-start; }
.avatar { flex: none; width: 34px; height: 34px; padding: 5px; border-radius: 11px; background: #FFFFFF; border: 1px solid #E6E3DB; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; }
.avatar span { border-radius: 3px; }
.avatar span:nth-child(1) { background: #93AEEE; } .avatar span:nth-child(2), .avatar span:nth-child(3) { background: #AF92EA; } .avatar span:nth-child(4) { background: #EA9C78; }
.avatar.work span { animation: sq 1s ease-in-out infinite; }
.avatar.work span:nth-child(2) { animation-delay: .25s; } .avatar.work span:nth-child(4) { animation-delay: .5s; } .avatar.work span:nth-child(3) { animation-delay: .75s; }
.bot-body { flex: 1; min-width: 0; }
.answer { font-size: 16px; line-height: 1.7; color: #2A2836; padding-top: 6px; overflow-wrap: anywhere; }
.answer p { margin: 0 0 12px; }
.answer p:last-child { margin-bottom: 0; }
.answer code { font-family: 'Geist Mono', monospace; font-size: 14px; background: #ECE9E2; padding: 1px 5px; border-radius: 5px; }
.answer pre { background: #1E1C2E; color: #ECEAF6; padding: 14px 16px; border-radius: 12px; overflow-x: auto; margin: 0 0 12px; }
.answer pre code { background: none; padding: 0; color: inherit; font-size: 13px; }
.answer ul, .answer ol { margin: 0 0 12px; padding-left: 22px; }
.answer h3 { margin: 6px 0 8px; font-size: 17px; }
.caret { display: inline-block; width: 8px; height: 1.05em; background: #4A3FB8; vertical-align: -3px; margin-left: 2px; animation: blink 1s steps(1) infinite; }
.meta { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; font-family: 'Geist Mono', monospace; font-size: 12px; color: #8A86A8; }
.meta span { padding: 5px 10px; border-radius: 999px; background: #FFFFFF; border: 1px solid #E6E3DB; }
.err { color: #A0502C; }

/* ---------- token factory ---------- */
.factory { padding: 16px 18px 18px; border-radius: 20px; background: #FFFFFF; border: 1px solid #E6E3DB; box-shadow: 0 10px 30px rgba(22,21,31,0.05); margin-bottom: 14px; }
.factory-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.f-label { font-size: 15px; font-weight: 500; }
.f-meta { font-family: 'Geist Mono', monospace; font-size: 12px; color: #A9A5BA; font-variant-numeric: tabular-nums; }
.line { display: flex; align-items: stretch; }
.station { display: flex; flex-direction: column; }
.belt-in, .belt-out { flex: 1.1 1 0; min-width: 0; }
.machine { flex: 0 0 92px; align-items: center; }
.rack-st { flex: 0 0 104px; align-items: center; padding: 0 8px; }
.st-label { font-family: 'Geist Mono', monospace; font-size: 9px; letter-spacing: .1em; color: #A9A5BA; margin-bottom: 6px; }
.st-label.right { text-align: right; }
.belt { position: relative; flex: 1; min-height: 64px; overflow: hidden; }
.chips { position: absolute; inset: 0; }
.tok { position: absolute; bottom: 20px; padding: 3px 7px; border-radius: 7px; font-family: 'Geist Mono', monospace; font-size: 11px; white-space: pre; will-change: left, opacity; }
.tread { position: absolute; left: 0; right: 0; bottom: 12px; height: 6px; border-radius: 3px; background-image: repeating-linear-gradient(90deg, #D9D5CC 0 8px, #ECE9E2 8px 16px); }
.factory.running .tread { animation: tread .5s linear infinite; }
.router { position: relative; width: 84px; height: 64px; border-radius: 12px; background: #2E2A5C; box-shadow: inset 0 -6px 0 rgba(0,0,0,0.18); overflow: hidden; }
.router .g1, .router .g2 { transform-box: fill-box; transform-origin: center; }
.factory.running .g1 { animation: gear 2.2s linear infinite; }
.factory.running .g2 { animation: gearR 1.4s linear infinite; }
.factory.running .led { animation: led .8s ease-in-out infinite; }
.rack { width: 88px; height: 64px; padding: 6px; border-radius: 12px; background: #F6F5F1; border: 1px solid #ECE9E2; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.rack span { border-radius: 4px; background: #E2DFD7; transition: background .2s, box-shadow .2s; }

/* ---------- composer ---------- */
.composer-wrap { padding: 12px 20px 22px; }
.composer { max-width: 780px; margin: 0 auto; display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 20px; border-radius: 999px; background: #FFFFFF; border: 1px solid #E6E3DB; box-shadow: 0 14px 40px rgba(22,21,31,0.08); }
.composer input { flex: 1; min-width: 0; min-height: 46px; border: 0; outline: none; background: transparent; color: #16151F; font-family: inherit; font-size: 16px; }
.send-btn, .stop-btn { width: 46px; height: 46px; flex: none; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
.send-btn { border: 0; background: #2E2A5C; transition: transform .2s, box-shadow .2s; }
.send-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(46,42,92,.3); }
.stop-btn { border: 1px solid #E6E3DB; background: #F6F5F1; }
.stop-btn:hover { background: #FFFFFF; }
.send-btn[hidden], .stop-btn[hidden] { display: none; }

@media (max-width: 760px) {
  .side { display: none; }
  .rack-st { flex-basis: 84px; padding: 0 4px; }
  .rack { width: 76px; }
  .machine { flex-basis: 80px; }
}
@media (max-width: 480px) {
  .belt-in { display: none; }
  .machine { flex-basis: 88px; }
  .factory { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, .factory.running .tread, .factory.running .g1, .factory.running .g2 { animation: none !important; transition: none !important; }
}
.st-label{display:none}

/* ---------- model picker ---------- */
.picker { position: relative; flex: none; }
.picker-btn { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px; border-radius: 999px; background: #FFFFFF; border: 1px solid #E6E3DB; font-family: 'Geist Mono', monospace; font-size: 12px; color: #2A2836; cursor: pointer; transition: border-color .2s, box-shadow .2s; }
.picker-btn:hover, .picker-btn[aria-expanded="true"] { border-color: #D9D5CC; box-shadow: 0 6px 16px rgba(22,21,31,0.06); }
.picker-btn:disabled { cursor: default; opacity: .7; }
.picker-menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; width: 290px; padding: 6px; border-radius: 16px; background: #FFFFFF; border: 1px solid #E6E3DB; box-shadow: 0 20px 50px rgba(22,21,31,0.14); animation: msgIn .18s ease both; }
.picker-menu[hidden] { display: none; }
.opt { display: flex; gap: 12px; align-items: flex-start; width: 100%; padding: 12px; border: 0; border-radius: 11px; background: transparent; text-align: left; cursor: pointer; color: #16151F; font-family: inherit; }
.opt:hover:not(:disabled) { background: #F6F5F1; }
.opt:disabled { cursor: not-allowed; }
.opt .mark { flex: none; width: 18px; height: 18px; margin-top: 1px; border-radius: 50%; border: 1.5px solid #D9D5CC; display: grid; place-items: center; }
.opt[aria-selected="true"] .mark { border-color: #2E2A5C; }
.opt[aria-selected="true"] .mark::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #2E2A5C; }
.opt .name { display: block; font-size: 14px; font-weight: 500; }
.opt .note { display: block; margin-top: 3px; font-size: 12px; color: #8A86A8; line-height: 1.4; }
.opt .state { display: block; margin-top: 5px; font-family: 'Geist Mono', monospace; font-size: 11px; color: #A9A5BA; }
.opt:disabled .name, .opt:disabled .note { opacity: .55; }
