:root {
  --bg: #f1f5f0;
  --bg-strong: #e7eee7;
  --panel: #fbfdfb;
  --panel-strong: #ffffff;
  --ink: #1d2a22;
  --muted: #76837a;
  --faint: #9ba69e;
  --line: #dfe7df;
  --line-strong: #cbd8cc;
  --green: #178652;
  --green-dark: #0c6d40;
  --green-soft: #e7f7ed;
  --amber: #a96b15;
  --amber-soft: #fff7e9;
  --red: #b0423d;
  --red-soft: #fff0ee;
  --blue: #46719a;
  --shadow: 0 18px 50px rgba(28, 48, 35, 0.08);
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(202, 229, 209, 0.62), transparent 32%),
    radial-gradient(circle at 90% 0%, rgba(228, 238, 226, 0.9), transparent 35%),
    var(--bg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg { display: block; fill: none; stroke: currentColor; stroke-width: 1.45; stroke-linecap: round; stroke-linejoin: round; }

.app-shell { min-height: 100vh; }
.brand { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 9px;
  background: linear-gradient(145deg, #53d88b, #129251);
  box-shadow: 0 5px 12px rgba(20, 137, 76, 0.2), inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}
.brand-mark::before {
  content: "";
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255, 255, 255, 0.95);
  border-radius: 50%;
}
.brand-mark span {
  position: absolute;
  right: 7px;
  bottom: 6px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #fff;
}
.brand-copy { display: flex; flex-direction: column; min-width: 0; }
.brand-copy strong { font-size: 14px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.brand-copy small { margin-top: 2px; color: var(--faint); font-family: var(--mono); font-size: 7.5px; letter-spacing: 0.15em; }
.brand-large .brand-mark { width: 38px; height: 38px; border-radius: 12px; }
.brand-large .brand-copy strong { font-size: 17px; }
.brand-large .brand-copy small { font-size: 8px; }

/* Login */
.login-shell {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 44px 22px 70px;
}
.login-glow { position: absolute; border-radius: 50%; filter: blur(2px); pointer-events: none; }
.login-glow-a { width: 460px; height: 460px; top: -220px; left: -150px; background: radial-gradient(circle, rgba(146, 211, 163, 0.3), transparent 68%); }
.login-glow-b { width: 520px; height: 520px; right: -260px; bottom: -300px; background: radial-gradient(circle, rgba(218, 227, 193, 0.38), transparent 68%); }
.login-card {
  position: relative;
  z-index: 1;
  width: min(100%, 590px);
  padding: 32px 34px 24px;
  border: 1px solid rgba(206, 221, 207, 0.9);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.94), rgba(249, 252, 248, 0.9));
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}
.login-intro { margin-top: 35px; }
.eyebrow { display: block; color: #7e8d83; font-family: var(--mono); font-size: 9px; font-weight: 650; letter-spacing: 0.13em; }
.login-intro h1 { margin: 13px 0 14px; font-size: clamp(29px, 5vw, 42px); line-height: 1.17; letter-spacing: -0.06em; font-weight: 680; }
.login-intro p { max-width: 440px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.75; }
.login-form { margin-top: 34px; padding-top: 18px; border-top: 1px solid var(--line); }
.login-form label { display: block; margin-bottom: 9px; color: #58685d; font-size: 11px; font-weight: 600; }
.password-row { display: flex; gap: 9px; }
.password-row input {
  min-width: 0;
  flex: 1;
  height: 42px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  outline: none;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.password-row input:focus { border-color: #62a979; box-shadow: 0 0 0 3px rgba(56, 160, 100, 0.12); }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 600;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, color 140ms ease;
}
.button:active { transform: translateY(1px); }
.button svg { width: 14px; height: 14px; }
.button-primary { color: #fff; background: #1d2921; border-color: #1d2921; box-shadow: 0 4px 10px rgba(25, 40, 30, 0.15); }
.button-primary:hover { background: #2b3b2e; }
.button-primary:disabled { cursor: not-allowed; opacity: 0.45; transform: none; }
.button-quiet { color: #68776d; background: transparent; border-color: var(--line); }
.button-quiet:hover { color: var(--ink); background: #f4f8f3; }
.button-small { min-height: 32px; padding: 0 10px; font-size: 11px; }
.password-row .button { flex: none; min-width: 128px; }
.login-error { margin: 10px 0 0; color: var(--red); font-size: 11px; }
.login-foot { display: flex; align-items: center; gap: 7px; margin-top: 25px; color: var(--faint); font-size: 10px; }
.secure-dot { width: 5px; height: 5px; border-radius: 50%; background: #44a76c; box-shadow: 0 0 0 3px #e7f5ea; }
.login-side-note {
  position: absolute;
  bottom: 26px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 11px;
  transform: translateX(-50%);
  color: #a7b1a9;
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.09em;
  white-space: nowrap;
}
.note-line { width: 33px; height: 1px; background: #c9d4cb; }

/* Service shell */
.service-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 62px;
  padding: 0 max(22px, calc((100vw - 1120px) / 2));
  border-bottom: 1px solid rgba(218, 229, 219, 0.75);
  background: rgba(249, 252, 248, 0.82);
  backdrop-filter: blur(18px);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 13px; }
.topbar-divider { width: 1px; height: 20px; background: var(--line); }
.topbar-title { color: #5d6a61; font-size: 12px; font-weight: 560; }
.account-label { color: var(--muted); font-family: var(--mono); font-size: 10px; }
.relay-state { display: inline-flex; align-items: center; gap: 6px; color: #57836a; font-size: 10px; white-space: nowrap; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: #4aaf73; box-shadow: 0 0 0 3px #e8f6ec; }
.relay-state.is-offline { color: #a27058; }
.relay-state.is-offline .dot { background: #d78965; box-shadow: 0 0 0 3px #fff1e9; }
.icon-button {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #6a786f;
  background: #fff;
}
.icon-button:hover { color: var(--ink); border-color: var(--line-strong); }
.icon-button svg { width: 15px; height: 15px; }
.service-main { width: min(1120px, calc(100% - 44px)); margin: 0 auto; padding: 48px 0 54px; flex: 1; }
body.is-embed .topbar { display: none; }
body.is-embed .service-main { padding-top: 28px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.page-heading h1 { margin: 10px 0 9px; font-size: clamp(25px, 3.4vw, 34px); line-height: 1.15; letter-spacing: -0.055em; font-weight: 680; }
.page-heading p { max-width: 570px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.device-count { display: flex; align-items: baseline; gap: 6px; padding-bottom: 4px; color: var(--faint); white-space: nowrap; }
.device-count strong { color: var(--ink); font-size: 25px; font-weight: 580; letter-spacing: -0.05em; }
.device-count span { font-size: 10px; }
.list-bar { display: flex; align-items: center; gap: 12px; margin-top: 42px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.list-label { color: #4f6154; font-size: 11px; font-weight: 650; }
.list-meta { color: var(--faint); font-size: 10px; }
.device-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 11px; margin-top: 14px; }
.device-card {
  position: relative;
  min-height: 154px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-align: left;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: 0 2px 6px rgba(31, 52, 37, 0.02);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.device-card:hover:not(:disabled) { transform: translateY(-2px); border-color: #b9d0bd; background: #fff; box-shadow: 0 10px 28px rgba(31, 59, 39, 0.08); }
.device-card:disabled { cursor: not-allowed; opacity: 0.73; }
.device-card-head { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 8px; }
.device-state { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 9px; }
.status-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: #c7cfc8; }
.status-dot.online { background: #3bb269; box-shadow: 0 0 0 3px #e4f7ea; }
.status-dot.offline { background: #d5775f; box-shadow: 0 0 0 3px #fff0eb; }
.status-dot.busy { background: #b1945c; box-shadow: 0 0 0 3px #f8f1e2; }
.device-arrow { color: #b2beb4; }
.device-arrow svg { width: 15px; height: 15px; }
.device-name { display: block; max-width: 100%; margin-top: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; font-weight: 650; letter-spacing: -0.035em; }
.device-meta { display: block; max-width: 100%; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--faint); font-family: var(--mono); font-size: 9px; }
.device-footer { display: flex; align-items: flex-end; justify-content: space-between; width: 100%; gap: 8px; margin-top: auto; padding-top: 20px; }
.device-last { color: #9aa69c; font-size: 9px; }
.device-lock { display: inline-flex; align-items: center; min-height: 22px; padding: 0 7px; border-radius: 5px; color: #9c752c; background: var(--amber-soft); font-size: 9px; }
.device-open-hint { color: #73a282; font-size: 9px; }
.empty-state { display: flex; flex-direction: column; align-items: center; padding: 65px 20px 58px; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 54px; height: 54px; border: 1px solid #dbe7dc; border-radius: 16px; color: #a5b9a8; background: #f9fcf8; }
.empty-icon svg { width: 29px; height: 29px; }
.empty-state h2 { margin: 17px 0 6px; font-size: 16px; font-weight: 630; letter-spacing: -0.03em; }
.empty-state p { margin: 0; color: var(--muted); font-size: 11px; }
.devices-note { display: flex; align-items: center; gap: 7px; margin-top: 29px; padding-top: 17px; border-top: 1px solid var(--line); color: #9aa69c; font-size: 9.5px; }
.note-icon { display: grid; place-items: center; width: 14px; height: 14px; border: 1px solid #cbd8cd; border-radius: 50%; color: #94a498; font-family: Georgia, serif; font-size: 9px; }

/* Session */
.session-view { max-width: 840px; margin: 0 auto; }
.session-heading { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.back-button { display: inline-flex; align-items: center; gap: 4px; padding: 5px 0; border: 0; color: #6d7c70; background: transparent; font-size: 10px; }
.back-button:hover { color: var(--ink); }
.back-button svg { width: 14px; height: 14px; }
.session-device { display: flex; align-items: center; gap: 10px; min-width: 0; margin-left: 22px; margin-right: auto; }
.session-status-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: #d5b56d; box-shadow: 0 0 0 4px #fcf5e6; }
.session-status-dot.online { background: #36ad67; box-shadow: 0 0 0 4px #e5f7eb; }
.session-status-dot.offline { background: #d57960; box-shadow: 0 0 0 4px #fff0eb; }
.session-device h1 { margin: 0; font-size: 18px; font-weight: 680; letter-spacing: -0.045em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-device p { margin: 3px 0 0; color: var(--faint); font-family: var(--mono); font-size: 8.5px; }
.session-heading > .button { flex: none; }
.session-banner { display: flex; align-items: center; gap: 8px; margin-top: 28px; padding: 10px 12px; border: 1px solid #dfeade; border-radius: 9px; color: #64836e; background: #f5faf4; font-size: 10px; }
.session-banner.is-warning { border-color: #f0dfbd; color: #9b752e; background: #fffaf0; }
.session-banner.is-error { border-color: #f0d6d1; color: #a15e53; background: #fff7f5; }
.session-banner-icon { display: grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; color: #fff; background: #75a784; font-size: 10px; font-weight: 700; }
.session-banner.is-error .session-banner-icon { background: #c78072; }
.transcript {
  min-height: 330px;
  max-height: min(58vh, 590px);
  overflow-y: auto;
  margin: 18px 0 0;
  padding: 20px 2px 26px;
  scrollbar-width: thin;
  scrollbar-color: #cbd8cd transparent;
}
.transcript:empty::before {
  content: "连接建立后，在这里查看远端消息和工具状态。";
  display: block;
  padding: 75px 0;
  color: #a5b0a7;
  text-align: center;
  font-size: 11px;
}
.message { display: flex; gap: 9px; margin: 0 0 17px; animation: message-in 180ms ease both; }
@keyframes message-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.message-role { display: grid; place-items: center; width: 25px; height: 25px; flex: none; border-radius: 7px; color: #fff; background: #76a184; font-family: var(--mono); font-size: 8px; font-weight: 650; }
.message-user { flex-direction: row-reverse; }
.message-user .message-role { color: #55755e; background: #e2f0e4; }
.message-body { min-width: 0; max-width: min(82%, 620px); }
.message-user .message-body { display: flex; flex-direction: column; align-items: flex-end; }
.message-meta { margin: 0 2px 4px; color: #9aa69c; font-family: var(--mono); font-size: 8px; }
.message-text { padding: 9px 12px; border: 1px solid #e6ede6; border-radius: 4px 11px 11px 11px; color: #344239; background: #fff; font-size: 13px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-user .message-text { border-color: #cde9d3; border-radius: 11px 4px 11px 11px; color: #1c5732; background: #dff7e5; }
.message-thought .message-text { color: #7f8d83; background: #f8faf7; border-style: dashed; font-size: 11px; }
.message-thought .message-role { color: #8a9a8e; background: #edf3ec; }
.thinking-dots { display: inline-flex; gap: 3px; vertical-align: middle; }
.thinking-dots i { width: 3px; height: 3px; border-radius: 50%; background: #aeb9b0; animation: blink 1s infinite; }
.thinking-dots i:nth-child(2) { animation-delay: 130ms; }
.thinking-dots i:nth-child(3) { animation-delay: 260ms; }
@keyframes blink { 0%, 65%, 100% { opacity: 0.35; } 35% { opacity: 1; } }
.tool-card, .approval-card, .plan-card { margin: 0 0 15px 34px; border: 1px solid #e1e9e1; border-radius: 10px; background: #fbfdfb; overflow: hidden; animation: message-in 180ms ease both; }
.tool-card-head, .approval-head, .plan-head { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 7px 11px; }
.tool-icon, .approval-icon { display: grid; place-items: center; width: 20px; height: 20px; flex: none; border-radius: 6px; color: #668b72; background: #eef7ef; font-family: var(--mono); font-size: 8px; }
.tool-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #52645a; font-size: 10px; font-weight: 600; }
.tool-kind { color: #a3afa5; font-family: var(--mono); font-size: 8px; }
.tool-status { margin-left: auto; color: #93a097; font-family: var(--mono); font-size: 8px; white-space: nowrap; }
.tool-status.completed { color: #4e9867; }
.tool-status.failed { color: #b86b5b; }
.tool-status.pending { color: #ae8a46; }
.tool-content, .approval-detail { margin: 0; padding: 8px 11px 10px; border-top: 1px solid #edf2ed; color: #77867b; font-family: var(--mono); font-size: 9px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 180px; overflow-y: auto; }
.tool-locations { display: flex; flex-wrap: wrap; gap: 5px; margin: 0 11px 9px; }
.tool-location { padding: 2px 5px; border-radius: 4px; color: #809087; background: #f0f5f0; font-family: var(--mono); font-size: 8px; }
.approval-card { border-color: #eadcbc; background: #fffdf8; }
.approval-card .tool-icon { color: #a57c2e; background: #fbf1dc; }
.approval-title { color: #7f632d; font-size: 10px; font-weight: 650; }
.approval-options { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 11px 11px; }
.approval-option { padding: 5px 8px; border: 1px solid #dfd0ad; border-radius: 5px; color: #80642c; background: #fff; font-size: 9px; }
.approval-option:hover { border-color: #bda269; background: #fff8e9; }
.approval-option.reject { color: #9a7560; border-color: #e3d7c6; }
.approval-option:disabled { cursor: default; opacity: 0.55; }
.approval-resolved { color: #9c8b68; font-size: 9px; }
.plan-card { background: #fbfcfb; }
.plan-title { color: #65756a; font-size: 10px; font-weight: 600; }
.plan-list { margin: 0; padding: 0 11px 9px 27px; color: #819085; font-size: 9px; line-height: 1.6; }
.plan-list li { margin: 2px 0; }
.plan-list li[data-status="completed"] { color: #7e9e85; text-decoration: line-through; }
.message-error .message-text { border-color: #efd8d3; color: #a45f53; background: #fff7f5; }
.message-error .message-role { color: #fff; background: #c88072; }
.composer-wrap { position: sticky; bottom: 0; padding: 13px 0 0; background: linear-gradient(180deg, rgba(241, 245, 240, 0), var(--bg) 22%); }
.composer { display: flex; align-items: flex-end; gap: 9px; padding: 9px; border: 1px solid var(--line-strong); border-radius: 13px; background: #fff; box-shadow: 0 8px 28px rgba(30, 54, 38, 0.07); }
.composer:focus-within { border-color: #8ab99a; box-shadow: 0 0 0 3px rgba(62, 166, 102, 0.1), 0 8px 28px rgba(30, 54, 38, 0.07); }
.composer textarea { flex: 1; min-height: 28px; max-height: 150px; resize: none; padding: 6px 4px; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 13px; line-height: 1.6; }
.composer textarea::placeholder { color: #a9b5ab; }
.composer-actions { display: flex; align-items: center; gap: 6px; }
.send-button { min-width: 70px; }
.composer-note { display: flex; justify-content: space-between; padding: 8px 3px 0; color: #a2aea4; font-family: var(--mono); font-size: 8px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 30; display: flex; align-items: center; gap: 8px; max-width: min(420px, calc(100vw - 44px)); padding: 10px 13px; border: 1px solid #cbe3d1; border-radius: 9px; color: #356345; background: #f3fbf5; box-shadow: 0 12px 30px rgba(28, 48, 35, 0.14); font-size: 10px; animation: toast-in 180ms ease both; }
.toast.is-error { border-color: #efd5cf; color: #a25b50; background: #fff7f5; }
.toast-dot { width: 6px; height: 6px; border-radius: 50%; background: #4cac71; }
.toast.is-error .toast-dot { background: #c97967; }
@keyframes toast-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 820px) {
  .device-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 15px; }
  .device-count { padding-bottom: 0; }
  .service-main { padding-top: 30px; }
}
@media (max-width: 560px) {
  .topbar { height: 56px; padding: 0 16px; }
  .topbar-divider, .topbar-title, .account-label { display: none; }
  .service-main { width: calc(100% - 28px); padding: 25px 0 35px; }
  .page-heading h1 { font-size: 25px; }
  .page-heading p { font-size: 11px; }
  .device-grid { grid-template-columns: 1fr; gap: 8px; }
  .device-card { min-height: 124px; padding: 14px; }
  .device-name { margin-top: 14px; font-size: 16px; }
  .list-bar { margin-top: 27px; }
  .session-device { margin-left: 9px; }
  .session-device h1 { font-size: 15px; }
  .session-heading { gap: 6px; }
  .session-heading > .button { padding: 0 8px; }
  .transcript { max-height: none; min-height: 260px; }
  .message-body { max-width: calc(100% - 32px); }
  .tool-card, .approval-card, .plan-card { margin-left: 0; }
  .composer-actions .button-quiet { display: none; }
  .login-card { padding: 24px 20px 20px; border-radius: 19px; }
  .login-intro { margin-top: 27px; }
  .login-intro h1 { font-size: 31px; }
  .password-row { flex-direction: column; }
  .password-row .button { width: 100%; }
  .login-side-note { font-size: 7px; }
  .toast { right: 14px; bottom: 14px; }
}
