:root {
  --bg: #0b1220;
  --bg2: #101a2c;
  --card: #16213a;
  --line: #23324f;
  --text: #e8eefc;
  --muted: #8ea0c0;
  --brand: #4da3ff;
  --me: #1f4fd8;
  --warn: #ff9f43;
  --err: #ff6b6b;
  --ok: #3ad29f;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 70% at 50% 0%, #16233d 0%, var(--bg) 60%);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--err); font-size: 13px; min-height: 20px; margin-top: 10px; }

/* 登录 */
#login { position: fixed; inset: 0; display: grid; place-items: center; padding: 26px; }
.login-card { width: 100%; max-width: 340px; text-align: center; }
.logo { font-size: 54px; line-height: 1; }
#login h1 { font-size: 18px; font-weight: 600; margin: 12px 0 6px; }
#login p { font-size: 13px; margin: 0 0 18px; }
#tokenInput {
  width: 100%; padding: 13px 15px; border-radius: 13px; font-size: 15px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); text-align: center;
}
#loginBtn { width: 100%; margin-top: 10px; }

/* 通用按钮 */
button {
  font: inherit; color: var(--text); border: 1px solid var(--line);
  background: var(--card); border-radius: 13px; padding: 11px 14px; cursor: pointer;
}
button:active { transform: scale(.985); filter: brightness(1.12); }
button:disabled { opacity: .55; }
button.primary {
  background: linear-gradient(135deg, #4da3ff, #2f6fd0); border-color: transparent;
  color: #fff; font-weight: 600;
}
button.warn { border-color: #5a2f33; color: #ffb3b3; background: #2a1a1e; }

/* 外壳 */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line); background: rgba(11,18,32,.86);
  backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 5;
}
.topbar .title { flex: 1; font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); flex: none; }
.dot.off { background: var(--err); box-shadow: 0 0 8px var(--err); }
#view { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* 列表 */
.list { padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 10px; padding: 13px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 15px;
}
.row:active { background: #1b2740; }
.row .main { flex: 1; min-width: 0; }
.row .name { font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 99px; border: 1px solid; }
.badge.run { color: var(--warn); border-color: #6a4a1c; }

/* 聊天 */
.chat { display: flex; flex-direction: column; height: 100%; }
.msgs { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 84%; padding: 10px 13px; border-radius: 15px; font-size: 14.5px;
  white-space: pre-wrap; word-break: break-word;
}
.msg.bot .bubble { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg.user .bubble { background: var(--me); border-bottom-right-radius: 5px; }
.bubble p { margin: 0 0 6px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble code { background: #0d1526; padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.bubble pre { background: #0d1526; padding: 10px; border-radius: 10px; overflow-x: auto; font-size: 12.5px; }
.bubble pre code { background: none; padding: 0; }
.bubble strong { color: #fff; }
.typing { display: flex; align-items: center; gap: 6px; padding: 2px 16px 10px; color: var(--muted); font-size: 12px; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,100% { opacity: .25 } 40% { opacity: 1 } }
.composer {
  display: flex; gap: 8px; padding: 10px 12px calc(10px + var(--safe-b));
  border-top: 1px solid var(--line); background: rgba(11,18,32,.92); backdrop-filter: blur(10px);
}
#input {
  flex: 1; resize: none; min-height: 44px; max-height: 132px; padding: 11px 13px; border-radius: 13px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; line-height: 1.45;
}
#send { width: 62px; background: linear-gradient(135deg, #4da3ff, #2f6fd0); border-color: transparent; color: #fff; font-weight: 600; }

/* 服务 */
.cards { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .st { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.btns { display: flex; gap: 8px; }
.btns button { flex: 1; padding: 10px 8px; font-size: 13.5px; }

/* 新会话 */
.newbox { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.picker { display: flex; flex-wrap: wrap; gap: 8px; }
.picker button { padding: 8px 13px; border-radius: 99px; font-size: 13px; }
.picker button.on { border-color: var(--brand); color: var(--brand); background: #14243c; }
#cwd { width: 100%; padding: 12px 14px; border-radius: 13px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; }

/* 标签栏 */
.tabbar {
  display: flex; border-top: 1px solid var(--line); background: rgba(11,18,32,.96);
  backdrop-filter: blur(12px); padding-bottom: var(--safe-b);
}
.tab { flex: 1; border: 0; background: none; padding: 8px 0 7px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); border-radius: 0; }
.tab span { font-size: 19px; line-height: 1; }
.tab i { font-style: normal; font-size: 11px; }
.tab.active { color: var(--brand); }

/* 启动遮罩 */
#splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); font-size: 15px; color: var(--muted); }
