:root {
  --bg: #FAF9F5;
  --surface: #FFFFFF;
  --surface-2: #F3F1EA;
  --line: #E6E2D6;
  --text: #1F1E1B;
  --muted: #6F6B60;
  --accent: #C2663E;
  --accent-soft: #F6E7DF;
  --ok: #3E7C5A;
  --warn: #B2541B;
  --kepu: #3B6EA8;
  --kepu-soft: #E4EDF7;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1B1A17; --surface: #24221F; --surface-2: #2C2A26; --line: #3A372F;
    --text: #EDEAE2; --muted: #A39E91; --accent: #E0855B; --accent-soft: #3A2A21;
    --ok: #7DBA94; --warn: #E59A62; --kepu: #8DB5E5; --kepu-soft: #22303F;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.65 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
#app { display: grid; grid-template-columns: 260px minmax(0, 1fr) 380px; height: 100vh; height: 100dvh; }

/* sidebar */
#sidebar { border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px; gap: 12px; background: var(--bg); min-height: 0; }
.brand { font-weight: 600; letter-spacing: .02em; }
.logo { color: var(--accent); }
.contact { display: flex; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.avatar { position: relative; width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 20px; font-weight: 600; flex: none; }
.avatar .live { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: var(--ok); border: 2px solid var(--surface); animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(.75); opacity: .6; } }
.name { font-weight: 600; }
.sub { color: var(--muted); font-size: 12px; }
.contact-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 18px; padding: 6px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); }
.side-label { color: var(--muted); font-size: 12px; margin-top: 4px; }
#session-list { list-style: none; padding: 0; margin: 0; overflow: auto; flex: 1; min-height: 0; }
#session-list li { display: flex; align-items: center; gap: 4px; padding: 7px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
#session-list li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#session-list li.on, #session-list li:hover { background: var(--surface-2); }
#session-list li button { opacity: 0; border: 0; background: none; cursor: pointer; color: var(--muted); }
#session-list li:hover button { opacity: 1; }
.side-foot { font-size: 11px; color: var(--muted); line-height: 1.5; }

/* chat */
#chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.chat-head .title { flex: 1; display: flex; gap: 10px; align-items: center; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.ok { color: var(--ok); }
.pill.bad { color: var(--warn); }
#btn-menu, #btn-panel { display: none; }
#messages { flex: 1; overflow: auto; padding: 24px max(16px, calc((100% - 760px) / 2)); }
#welcome { text-align: center; padding: 6vh 0 0; }
.w-avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 28px; font-weight: 600; display: grid; place-items: center; margin: 0 auto 12px; }
#welcome h1 { font-size: 24px; margin: 6px 0; font-weight: 600; }
#welcome p { color: var(--muted); margin: 0 auto 20px; max-width: 520px; }
.suggest { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px; text-align: left; }
.suggest button { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; cursor: pointer; font-size: 14px; }
.suggest button:hover { border-color: var(--accent); }
.msg { margin: 0 0 22px; display: flex; gap: 12px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--accent-soft); border-radius: 14px 14px 4px 14px; padding: 9px 14px; max-width: 80%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.bot .av { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 14px; font-weight: 600; flex: none; margin-top: 2px; }
.msg.bot .body { flex: 1; min-width: 0; }
.answer { overflow-wrap: anywhere; }
.answer p { margin: 0 0 10px; }
.answer h3, .answer h4 { margin: 14px 0 6px; font-size: 15px; }
.answer ul, .answer ol { margin: 0 0 10px; padding-left: 22px; }
.answer code { font-family: var(--mono); font-size: 13px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.answer.streaming::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.cite { display: inline-block; font-size: 11px; line-height: 1; padding: 3px 5px; margin: 0 1px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); cursor: pointer; vertical-align: 2px; border: 0; }
.cite.k { background: var(--kepu-soft); color: var(--kepu); }
.meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
.tag { padding: 1px 7px; border-radius: 999px; background: var(--surface-2); }
.tag.warn { color: var(--warn); }
.meta button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.meta button:hover { background: var(--surface-2); color: var(--text); }
.meta button.on { color: var(--accent); }
.alert { font-size: 13px; padding: 7px 10px; border-left: 3px solid var(--warn); background: var(--accent-soft); border-radius: 6px; margin-bottom: 8px; }
.err { color: var(--warn); }

#composer { padding: 10px max(16px, calc((100% - 760px) / 2)) 14px; }
#input { width: 100%; resize: none; border: 1px solid var(--line); border-radius: 14px 14px 0 0; border-bottom: 0; padding: 12px 14px; background: var(--surface); max-height: 200px; outline: none; display: block; }
#input:focus { border-color: var(--accent); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 14px 14px; padding: 6px 8px 8px; background: var(--surface); }
.ctl { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.ctl select { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); padding: 3px 6px; font-size: 13px; color: var(--text); }
.ctl.chk { gap: 6px; }
.grow { flex: 1; }
#btn-mic.rec { background: var(--accent); color: #fff; }

/* panel */
#panel { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 8px; }
.tabs button { flex: 1; border: 0; background: none; padding: 12px 4px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-size: 14px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tab { display: none; overflow: auto; padding: 14px; flex: 1; min-height: 0; }
.tab.on { display: block; }
.empty, .muted { color: var(--muted); font-size: 13px; }
.search { display: flex; gap: 6px; margin-bottom: 10px; align-items: center; }
.search input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--surface); }
.search select { border: 1px solid var(--line); border-radius: 8px; padding: 5px; background: var(--surface); }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: var(--surface); font-size: 13px; }
.card .h { display: flex; gap: 6px; align-items: baseline; font-weight: 600; margin-bottom: 4px; }
.card .h .id { font-family: var(--mono); font-size: 11px; color: var(--accent); }
.card.k .h .id { color: var(--kepu); }
.card .t { color: var(--muted); max-height: 7.5em; overflow: hidden; }
.card.open .t { max-height: none; }
.card .yr { font-weight: 400; color: var(--muted); font-size: 12px; }
.card.click { cursor: pointer; }
.card.flash { border-color: var(--accent); }

.trace-node { position: relative; padding: 0 0 14px 22px; font-size: 13px; }
.trace-node::before { content: ""; position: absolute; left: 6px; top: 8px; bottom: -6px; width: 1px; background: var(--line); }
.trace-node:last-child::before { display: none; }
.trace-node .dot { position: absolute; left: 1px; top: 5px; width: 11px; height: 11px; border-radius: 50%; background: var(--accent); }
.trace-node .dot.err { background: var(--warn); }
.trace-node .n { font-weight: 600; display: flex; justify-content: space-between; }
.trace-node .n small { font-weight: 400; color: var(--muted); font-family: var(--mono); }
.trace-node .d { color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.trace-node pre, .reasoning { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; background: var(--surface-2); border-radius: 8px; padding: 8px; margin: 6px 0 0; max-height: 260px; overflow: auto; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }

/* call */
#call { position: fixed; inset: 0; background: #121110; color: #EDEAE2; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: max(24px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom)); }
#call[hidden] { display: none; }
.call-top { text-align: center; }
.call-name { font-size: 26px; font-weight: 600; }
.call-sub { color: #A39E91; font-size: 13px; }
#orb { width: min(70vw, 280px); height: min(70vw, 280px); }
#call-state { color: #CFC9BC; font-size: 15px; min-height: 1.6em; }
#call-sub-text { max-width: 640px; text-align: center; min-height: 4.5em; color: #EDEAE2; font-size: 16px; padding: 0 8px; }
.call-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.talk { width: 96px; height: 96px; border-radius: 50%; border: 0; background: #E0855B; color: #fff; font-size: 15px; cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: none; }
.talk.rec { background: #F2A27C; box-shadow: 0 0 0 10px rgba(224, 133, 91, .25); }
.hang { border: 0; background: #B2412B; color: #fff; padding: 8px 28px; border-radius: 999px; cursor: pointer; }
.handsfree { font-size: 13px; color: #A39E91; }

/* login + modal */
#login, #modal { position: fixed; inset: 0; background: rgba(20, 18, 15, .45); display: grid; place-items: center; z-index: 60; padding: 16px; }
#login[hidden], #modal[hidden] { display: none; }
#login-form { background: var(--surface); padding: 28px; border-radius: 16px; width: min(340px, 100%); text-align: center; display: grid; gap: 10px; }
#login-form h2 { margin: 0; font-size: 18px; }
#login-form input { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--bg); }
.modal-card { background: var(--surface); border-radius: 16px; width: min(720px, 100%); max-height: 85vh; overflow: auto; padding: 18px 20px; position: relative; }
.modal-card .close { position: absolute; right: 10px; top: 10px; }
.modal-body { white-space: pre-wrap; font-size: 14px; overflow-wrap: anywhere; }
.modal-body h3 { margin: 0 30px 8px 0; white-space: normal; }

/* responsive */
@media (max-width: 1180px) {
  #app { grid-template-columns: 240px minmax(0, 1fr); }
  #panel { position: fixed; right: 0; top: 0; bottom: 0; width: min(400px, 92vw); z-index: 30; transform: translateX(100%); transition: transform .2s; box-shadow: -8px 0 24px rgba(0,0,0,.08); }
  #panel.open { transform: none; }
  #btn-panel { display: block; }
}
@media (max-width: 760px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(280px, 86vw); z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: 8px 0 24px rgba(0,0,0,.08); }
  #sidebar.open { transform: none; }
  #btn-menu { display: block; }
  #messages { padding: 16px; }
  #composer { padding: 8px 10px 12px; }
  .msg.user .bubble { max-width: 90%; }
  .ctl span { display: none; }
}
