:root {
  --bg: #14130f;
  --panel: #1c1b16;
  --panel-2: #24231d;
  --line: #34322a;
  --text: #ece8dc;
  --muted: #9a9585;
  --accent: #e0894f;
  --accent-ink: #1a120b;
  --ok: #7fbf7a;
  --bad: #e06b5f;
  --warn: #d9b35a;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --r: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); -webkit-text-size-adjust: 100%; overflow: hidden; }
[hidden] { display: none !important; }
code, pre { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
a { color: var(--accent); }

.brand { font-weight: 500; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; }
.brand b { font-weight: 700; }
.mark { color: var(--accent); }
.mark.big { font-size: 40px; line-height: 1; }

.btn { appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 10px; padding: 10px 14px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: 0; color: var(--text); font-size: 20px; padding: 6px 10px; cursor: pointer; }
.link { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 4px 0; text-decoration: underline; text-underline-offset: 3px; }
.danger-text { color: var(--bad); }
input, textarea, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
select { width: auto; padding: 6px 8px; font-size: 13px; }

/* login */
.login { height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; }
.login-card .brand { font-size: 22px; }
.login-card p { margin: 0; }
.err { color: var(--bad); min-height: 1.2em; font-size: 14px; }

/* layout */
.app { display: grid; grid-template-columns: 290px 1fr; height: 100%; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; padding: calc(14px + var(--safe-t)) 12px calc(12px + var(--safe-b)); min-height: 0; }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 2px 4px; }
.session-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.session-list .group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 12px 8px 4px; }
.sess { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 9px 10px; border-radius: 9px; cursor: pointer; font: inherit; }
.sess:hover { background: var(--panel-2); }
.sess.active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.sess .t { display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess .p { font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--line); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(127,191,122,.6); } 100% { box-shadow: 0 0 0 7px rgba(127,191,122,0); } }
.side-foot { display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.usage { font-size: 12px; color: var(--muted); display: grid; gap: 4px; }
.usage .bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.usage .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.top { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-t)) 16px 10px; border-bottom: 1px solid var(--line); background: var(--bg); }
.top-title { flex: 1; min-width: 0; }
.top-title div { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-title small { display: block; font-family: var(--mono); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.run { color: var(--ok); border-color: var(--ok); }
.pill.run::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 6px; animation: pulse 1.6s infinite; }

.feed { flex: 1; overflow-y: auto; padding: 18px 16px 24px; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }
.feed > * { max-width: 860px; width: 100%; margin-left: auto; margin-right: auto; }
.empty { margin: auto; text-align: center; display: grid; gap: 10px; justify-items: center; max-width: 440px !important; }
.empty h2 { margin: 6px 0 0; font-size: 20px; }

.msg-user { align-self: flex-end; max-width: min(85%, 700px) !important; margin-right: 0 !important; background: var(--panel-2); border: 1px solid var(--line); border-radius: 16px 16px 4px 16px; padding: 10px 14px; white-space: pre-wrap; word-break: break-word; }
.feed > .msg-user { margin-left: auto; }
.msg-user .meta { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: right; }
.msg-text { word-break: break-word; }
.msg-text p { margin: 0 0 .6em; }
.msg-text p:last-child { margin-bottom: 0; }
.msg-text pre { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; overflow-x: auto; margin: .5em 0; }
.msg-text code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }
.msg-text pre code { background: none; padding: 0; }
.msg-text ul, .msg-text ol { margin: .3em 0 .6em; padding-left: 1.3em; }
.msg-text h1, .msg-text h2, .msg-text h3, .msg-text h4 { font-size: 1.02em; margin: .8em 0 .3em; }

details.tool, details.think { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 13.5px; }
details.tool > summary, details.think > summary { list-style: none; cursor: pointer; padding: 8px 12px; display: flex; gap: 8px; align-items: center; min-width: 0; }
details > summary::-webkit-details-marker { display: none; }
.tool .ic { width: 18px; text-align: center; flex: none; }
.tool .nm { font-weight: 600; flex: none; }
.tool .sm { font-family: var(--mono); font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.tool .st { flex: none; font-size: 12px; }
.tool .st.wait { color: var(--warn); }
.tool .st.ok { color: var(--ok); }
.tool .st.bad { color: var(--bad); }
.tool pre, .think pre { margin: 0; padding: 10px 12px; border-top: 1px solid var(--line); max-height: 360px; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 12.5px; }
.tool pre.out.bad { color: var(--bad); }
.think > summary { color: var(--muted); font-style: italic; }

.result { font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 2px 2px 8px; border-bottom: 1px dashed var(--line); }
.result.bad { color: var(--bad); }
.errbox { border: 1px solid var(--bad); background: rgba(224,107,95,.08); color: #f3b4ad; border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; }
.working { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.working i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: blink 1s infinite; }
.working i:nth-child(2) { animation-delay: .2s; } .working i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }

.composer { border-top: 1px solid var(--line); background: var(--bg); padding: 10px 12px calc(10px + var(--safe-b)); }
.composer > * { max-width: 860px; margin: 0 auto; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; max-height: 40vh; min-height: 44px; line-height: 1.4; font-size: 16px; }
.send { width: 46px; height: 44px; padding: 0; font-size: 18px; flex: none; }
.composer-opts { display: flex; gap: 14px; align-items: center; margin-top: 8px !important; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.composer-opts label { display: flex; gap: 6px; align-items: center; }
.composer-opts .link { margin-left: auto; }

.dlg { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 16px; padding: 0; width: min(440px, calc(100% - 32px)); }
.dlg::backdrop { background: rgba(0,0,0,.6); }
.dlg form { display: grid; gap: 14px; padding: 22px; }
.dlg h3 { margin: 0; }
.dlg label { display: grid; gap: 6px; font-size: 14px; }
.dlg select { width: 100%; padding: 10px 12px; font-size: 15px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

.scrim { display: none; }
.only-mobile { display: none; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-block; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(310px, 86vw); z-index: 20; transform: translateX(-102%); transition: transform .22s ease; }
  .app.side-open .side { transform: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 10; }
  .top { padding-left: 6px; }
  .feed { padding: 14px 12px 20px; }
}
