:root {
  color-scheme: dark;
  --bg: #0b0f16;
  --bg-elev: #121824;
  --bg-elev-2: #18202e;
  --line: #232c3b;
  --text: #e6edf7;
  --text-dim: #96a3b8;
  --text-faint: #6b788c;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.16);
  --green: #3fb950;
  --red: #f4696b;
  --amber: #e3b341;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  overscroll-behavior-y: none;
}

body {
  height: 100dvh;
  overflow: hidden;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.boot {
  margin: auto;
  text-align: center;
  color: var(--text-dim);
}
.boot-logo {
  font-size: 44px;
  color: var(--accent);
  animation: pulse 1.6s ease-in-out infinite;
}
.boot-text {
  margin-top: 10px;
  font-size: 14px;
}
@keyframes pulse {
  0%, 100% { opacity: 0.45; transform: scale(0.96); }
  50% { opacity: 1; transform: scale(1.04); }
}

/* ---------------------------------------------------------------- 顶栏 */

.topbar {
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 15, 22, 0.92);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 54px;
}
.topbar h1 {
  font-size: 17px;
  font-weight: 650;
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .sub {
  font-size: 11.5px;
  color: var(--text-faint);
  font-weight: 400;
  display: block;
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 19px;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: none;
}
.icon-btn:active {
  background: var(--bg-elev-2);
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  flex: none;
  box-shadow: 0 0 6px rgba(63, 185, 80, 0.7);
}
.dot.off {
  background: var(--red);
  box-shadow: 0 0 6px rgba(244, 105, 107, 0.7);
}
.dot.wait {
  background: var(--amber);
  box-shadow: 0 0 6px rgba(227, 179, 65, 0.7);
}

/* ---------------------------------------------------------------- 滚动区 */

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(76px + var(--safe-bottom));
}

/* ---------------------------------------------------------------- 列表 */

.section-head {
  padding: 16px 16px 6px;
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-head .count {
  color: var(--text-faint);
  font-size: 11px;
}

.ws-card {
  margin: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elev);
}
.ws-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
}
.ws-ico {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 14px;
  flex: none;
}
.ws-title {
  flex: 1;
  min-width: 0;
}
.ws-title b {
  display: block;
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ws-title span {
  display: block;
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  unicode-bidi: plaintext;
}
.ws-add {
  border: 0;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  border-radius: 10px;
  width: 30px;
  height: 30px;
  font-size: 17px;
  line-height: 1;
  flex: none;
}
.ws-caret {
  color: var(--text-faint);
  font-size: 11px;
  flex: none;
  width: 12px;
  text-align: center;
}
.ws-body {
  border-top: 1px solid var(--line);
  display: none;
}
.ws-card.open .ws-body {
  display: block;
}
.ws-empty {
  padding: 14px;
  color: var(--text-faint);
  font-size: 13px;
}

.row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 14px;
  border-top: 1px solid rgba(35, 44, 59, 0.55);
  cursor: pointer;
  position: relative;
}
.row:first-child {
  border-top: 0;
}
.row:active {
  background: var(--bg-elev-2);
}
.row-main {
  flex: 1;
  min-width: 0;
}
.row-title {
  font-size: 14.5px;
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.row-meta {
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--text-faint);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.chip {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-size: 10.5px;
  line-height: 1.5;
}
.chip.run {
  background: rgba(63, 185, 80, 0.15);
  color: var(--green);
}
.chip.error {
  background: rgba(244, 105, 107, 0.15);
  color: var(--red);
}
.chip.danger {
  background: rgba(244, 105, 107, 0.14);
  color: var(--red);
  font-size: 12px;
}

/* ---------------------------------------------------------------- 聊天 */

.chat {
  padding: 14px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100%;
  justify-content: flex-end;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 100%;
}
.msg .bubble {
  border-radius: 16px;
  padding: 10px 13px;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 14.5px;
}
.msg.user {
  align-items: flex-end;
}
.msg.user .bubble {
  background: linear-gradient(180deg, #2b6fe6, #245fc9);
  color: #fff;
  border-bottom-right-radius: 6px;
  max-width: 86%;
  white-space: pre-wrap;
}
.msg.assistant .bubble {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.msg .who {
  font-size: 10.5px;
  color: var(--text-faint);
  margin: 0 6px 4px;
}

.md p {
  margin: 0 0 8px;
}
.md p:last-child {
  margin-bottom: 0;
}
.md pre {
  background: #0a0e15;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
  margin: 8px 0;
  max-height: 380px;
}
.md code {
  font-family: 'Cascadia Mono', Consolas, 'SF Mono', Menlo, monospace;
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.92em;
}
.md pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}
.md a {
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
}
.md ul,
.md ol {
  margin: 6px 0;
  padding-left: 20px;
}
.md blockquote {
  margin: 8px 0;
  padding-left: 10px;
  border-left: 3px solid var(--line);
  color: var(--text-dim);
}
.md h1,
.md h2,
.md h3,
.md h4 {
  font-size: 15px;
  margin: 10px 0 6px;
}
.md table {
  border-collapse: collapse;
  font-size: 13px;
  margin: 8px 0;
  display: block;
  overflow-x: auto;
}
.md th,
.md td {
  border: 1px solid var(--line);
  padding: 4px 8px;
}
.md hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 10px 0;
}

.reasoning {
  margin: 0 0 8px;
  border-left: 2px solid var(--line);
  padding-left: 9px;
  color: var(--text-dim);
  font-size: 13px;
}
.reasoning summary {
  cursor: pointer;
  color: var(--text-faint);
  font-size: 12px;
  user-select: none;
  list-style: none;
}
.reasoning summary::-webkit-details-marker {
  display: none;
}
.reasoning[open] summary {
  margin-bottom: 6px;
}
.reasoning .rbody {
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
}

.tool {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  font-size: 13px;
  overflow: hidden;
}
.tool > summary {
  padding: 9px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  color: var(--text-dim);
}
.tool > summary::-webkit-details-marker {
  display: none;
}
.tool.ok > summary .tstate {
  color: var(--green);
}
.tool.err > summary .tstate {
  color: var(--red);
}
.tool.running > summary .tstate {
  color: var(--amber);
}
.tool .tname {
  color: var(--text);
  font-weight: 600;
  font-family: 'Cascadia Mono', Consolas, monospace;
  font-size: 12.5px;
}
.tool .targ {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'Cascadia Mono', Consolas, monospace;
  font-size: 11.5px;
  color: var(--text-faint);
}
.tool .tbody {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  max-height: 340px;
  overflow: auto;
  font-family: 'Cascadia Mono', Consolas, monospace;
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-dim);
}
.tool .tbody .lbl {
  color: var(--text-faint);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 6px 0 3px;
}

.note {
  align-self: center;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
  max-width: 90%;
}
.error-box {
  align-self: center;
  color: var(--red);
  background: rgba(244, 105, 107, 0.1);
  border: 1px solid rgba(244, 105, 107, 0.3);
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 12.5px;
  max-width: 94%;
}
.files {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  padding: 10px 12px;
  font-size: 13px;
}
.files div + div {
  margin-top: 4px;
}
.files .fname {
  color: var(--accent);
}

.live {
  opacity: 0.98;
}
.caret {
  display: inline-block;
  width: 7px;
  height: 15px;
  background: var(--accent);
  vertical-align: -2px;
  margin-left: 2px;
  animation: blink 1s steps(2) infinite;
  border-radius: 1px;
}
@keyframes blink {
  50% { opacity: 0; }
}

.load-more {
  text-align: center;
  padding: 8px;
}
.load-more button {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 12.5px;
}

/* ---------------------------------------------------------------- 输入框 */

.composer {
  border-top: 1px solid var(--line);
  background: rgba(11, 15, 22, 0.96);
  backdrop-filter: blur(14px);
  padding: 8px 10px calc(8px + var(--safe-bottom));
  display: flex;
  gap: 8px;
  align-items: flex-end;
  position: sticky;
  bottom: 0;
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.45;
  max-height: 38dvh;
  font-family: inherit;
  outline: none;
}
.composer textarea:focus {
  border-color: rgba(76, 141, 255, 0.6);
}
.send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  display: grid;
  place-items: center;
  flex: none;
  transition: transform 0.12s, background 0.2s;
}
.send:disabled {
  background: var(--bg-elev-2);
  color: var(--text-faint);
}
.send:active:not(:disabled) {
  transform: scale(0.93);
}
.send.stop {
  background: var(--red);
}

/* ---------------------------------------------------------------- 底部导航 */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(58px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: rgba(11, 15, 22, 0.96);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
  z-index: 30;
}
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-faint);
  text-decoration: none;
  font-size: 10.5px;
}
.tabbar a .ti {
  font-size: 19px;
  line-height: 1;
}
.tabbar a.on {
  color: var(--accent);
}

/* ---------------------------------------------------------------- 弹层 */

.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  animation: fade 0.16s ease;
}
@keyframes fade {
  from { opacity: 0; }
}
.sheet {
  width: 100%;
  background: var(--bg-elev);
  border-radius: 20px 20px 0 0;
  padding: 8px 12px calc(16px + var(--safe-bottom));
  max-height: 78dvh;
  overflow-y: auto;
  animation: rise 0.2s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes rise {
  from { transform: translateY(24px); opacity: 0.6; }
}
.sheet h3 {
  font-size: 15px;
  margin: 8px 8px 10px;
}
.sheet .opt {
  padding: 12px 10px;
  border-radius: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.sheet .opt:active {
  background: var(--bg-elev-2);
}
.sheet .opt .desc {
  font-size: 11.5px;
  color: var(--text-faint);
}
.sheet input[type='text'],
.sheet textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  margin-bottom: 10px;
}
.sheet .btns {
  display: flex;
  gap: 8px;
}
.sheet .btns button {
  flex: 1;
  padding: 11px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 14.5px;
}
.sheet .btns button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.sheet .btns button.danger {
  background: rgba(244, 105, 107, 0.14);
  border-color: rgba(244, 105, 107, 0.4);
  color: var(--red);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%) translateY(8px);
  background: rgba(30, 39, 54, 0.97);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 90;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  max-width: 86vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.empty {
  padding: 60px 24px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13.5px;
}
.empty .big {
  font-size: 34px;
  margin-bottom: 10px;
  opacity: 0.5;
}

.settings-group {
  margin: 12px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elev);
}
.settings-group .line {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  font-size: 13.5px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.settings-group .line:first-child {
  border-top: 0;
}
.settings-group .line .k {
  color: var(--text-dim);
  flex: none;
}
.settings-group .line .v {
  color: var(--text);
  text-align: right;
  word-break: break-all;
  font-size: 12.5px;
}
.settings-group .hint {
  padding: 12px 14px;
  font-size: 12.5px;
  color: var(--text-faint);
  line-height: 1.65;
  border-top: 1px solid var(--line);
}
.settings-group .hint b {
  color: var(--text-dim);
}

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(74px + var(--safe-bottom));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 25px;
  line-height: 1;
  box-shadow: 0 8px 24px rgba(76, 141, 255, 0.35);
  z-index: 25;
  display: grid;
  place-items: center;
}

.searchbar {
  padding: 8px 12px 2px;
}
.searchbar input {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
