:root {
  --bg: #0b0d12;
  --bg-soft: #141822;
  --fg: #e7ecf5;
  --fg-dim: #8b95a7;
  --accent: #5b8cff;
  --danger: #ff6b6b;
  --ok: #34d399;
  --warn: #fbbf24;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: calc(max(env(safe-area-inset-top, 0px), var(--sab-top, 0px)) + 8px) 14px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid #1d2230;
}

.brandbar,
.machinebar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brandbar .chip {
  margin-left: auto;
}

.logo {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  flex: none;
}

.brandname {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.machinebar {
  padding-left: 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--fg-dim);
}

.dot.ok {
  background: var(--ok);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 22%, transparent);
}

.dot.busy {
  background: var(--warn);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--warn) 22%, transparent);
}

.title {
  font-weight: 600;
  letter-spacing: 0.2px;
}

.meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chip {
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--fg-dim);
  border: 1px solid #222838;
}

.chip.busy {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 40%, #222838);
}

.chip.ok {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 40%, #222838);
}

.ghost {
  background: transparent;
  border: 1px solid #222838;
  color: var(--fg-dim);
  border-radius: 10px;
  width: 32px;
  height: 30px;
  font-size: 15px;
}

.log {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.msg.user {
  align-self: flex-end;
  background: linear-gradient(180deg, #2a4a9b, #23397a);
  border: 1px solid #33509f;
  border-bottom-right-radius: 6px;
}

/* Same bubble, but typed on the PC: neutral so both sides stay distinguishable. */
.msg.user.from-pc {
  align-self: flex-start;
  background: #1a2130;
  border-color: #2b3549;
  color: #cbd6e6;
  border-bottom-left-radius: 6px;
  border-bottom-right-radius: 14px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--bg-soft);
  border: 1px solid #1f2534;
  border-bottom-left-radius: 6px;
}

.msg.assistant.streaming::after {
  content: "▊";
  margin-left: 2px;
  opacity: 0.6;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.reasoning {
  margin: 0 0 6px;
  padding: 6px 8px;
  font-size: 12px;
  color: var(--fg-dim);
  border-left: 2px solid #2a3143;
  white-space: pre-wrap;
}

.tool {
  align-self: flex-start;
  max-width: 88%;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--fg-dim);
  background: #10141d;
  border: 1px dashed #232a3a;
  border-radius: 10px;
  padding: 6px 10px;
  word-break: break-all;
}

.sys {
  align-self: center;
  font-size: 12px;
  color: var(--fg-dim);
  padding: 2px 0;
}

.pair {
  margin: 0 14px 10px;
  padding: 12px;
  border: 1px solid #222838;
  border-radius: 14px;
  background: var(--bg-soft);
}

.pair .hint {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--fg-dim);
}

.cmd {
  display: block;
  font-size: 11px;
  color: #9fb4d8;
  background: #0d1119;
  border: 1px solid #1d2331;
  border-radius: 8px;
  padding: 6px 8px;
  margin-bottom: 10px;
  word-break: break-all;
}

.row {
  display: flex;
  gap: 8px;
}

input#code {
  flex: 1;
  min-width: 0;
  padding: 11px 12px;
  border-radius: 11px;
  border: 1px solid #222838;
  background: #0d1119;
  color: var(--fg);
  font: inherit;
  letter-spacing: 3px;
}

button {
  font: inherit;
  border-radius: 11px;
  border: 1px solid #2b3450;
  background: #1b2233;
  color: var(--fg);
  padding: 10px 14px;
}

button.primary {
  background: linear-gradient(180deg, #3c6ef0, #2f57c8);
  border-color: #3c6ef0;
  font-weight: 600;
}

button.danger {
  background: #3a1d22;
  border-color: #6c2b33;
  color: #ffc9cf;
}

button:disabled {
  opacity: 0.5;
}

.err {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--danger);
}

.composer {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px calc(max(env(safe-area-inset-bottom, 0px), var(--sab-bottom, 0px)) + 10px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid #1d2230;
}

textarea#text {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 40vh;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid #222838;
  background: #0d1119;
  color: var(--fg);
  font: inherit;
}

textarea#text:focus,
input#code:focus,
.field:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent);
  outline-offset: 1px;
}

/* ---------- machine switcher ---------- */

.machine {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 46vw;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid #222838;
  color: var(--fg);
  font-weight: 600;
  overflow: hidden;
}

.machine span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.caret {
  color: var(--fg-dim);
  font-size: 11px;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  background: rgba(4, 6, 10, 0.55);
  backdrop-filter: blur(2px);
}

.sheet[hidden] {
  display: none;
}

.sheet-card {
  width: 100%;
  max-height: 76vh;
  overflow-y: auto;
  padding: 16px 14px calc(max(env(safe-area-inset-bottom, 0px), var(--sab-bottom, 0px)) + 14px);
  background: #0f131c;
  border-top: 1px solid #222838;
  border-radius: 18px 18px 0 0;
}

.sheet-card h2 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
}

.machines {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.machine-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid #1f2534;
}

.machine-row.current {
  border-color: color-mix(in srgb, var(--accent) 45%, #1f2534);
}

.machine-row.empty {
  justify-content: center;
  color: var(--fg-dim);
  font-size: 13px;
}

.machine-pick {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.machine-title {
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.machine-code {
  font-size: 11px;
  color: var(--fg-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.machine-code b {
  color: var(--warn);
}

.machine-tools {
  display: flex;
  gap: 4px;
}

.link {
  padding: 6px 8px;
  border-radius: 9px;
  border: 1px solid #222838;
  background: transparent;
  color: var(--fg-dim);
  font-size: 12px;
}

.link.danger {
  color: #ffb4bb;
  border-color: #4a2329;
}

.sheet-actions {
  display: flex;
  gap: 8px;
}

.sheet-actions .primary {
  flex: 1;
}

.field {
  width: 100%;
  margin-bottom: 8px;
  padding: 11px 12px;
  border-radius: 11px;
  border: 1px solid #222838;
  background: #0d1119;
  color: var(--fg);
  font: inherit;
}

pre#paircmd {
  margin: 0;
  font-size: 11px;
  color: #9fb4d8;
  background: #0d1119;
  border: 1px solid #1d2331;
  border-radius: 8px;
  padding: 8px;
  white-space: pre-wrap;
  word-break: break-all;
}

.stop {
  width: auto;
  padding: 0 10px;
  height: 40px;
  color: var(--danger);
  border-color: #4a2329;
}

/* ---------- 消息操作条 / 失败态 / 提示 ---------- */
.msg-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 100%;
}
.msg-wrap.user { align-self: flex-end; align-items: flex-end; }
.msg-wrap.assistant { align-self: flex-start; align-items: flex-start; }
.msg-wrap .msg { max-width: 100%; }

.msg-actions {
  display: flex;
  gap: 6px;
  opacity: 0.35;
  transition: opacity 0.15s;
}
.msg-wrap:hover .msg-actions,
.msg-wrap:active .msg-actions { opacity: 1; }
.msg-wrap.failed .msg-actions { opacity: 1; }

.bubble-act {
  background: #151b26;
  border: 1px solid #232c3c;
  color: #9fb0c8;
  font-size: 12px;
  line-height: 1.6;
  padding: 1px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.bubble-act.danger { color: #f87171; border-color: #3a2530; }

.msg-failed { font-size: 12px; color: #f87171; }
.msg-wrap.failed .msg { border-color: #5a2530; }

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(max(env(safe-area-inset-bottom, 0px), var(--sab-bottom, 0px)) + 84px);
  background: #1b2434;
  border: 1px solid #2c384d;
  color: #dbe6f7;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 20;
}


.menu-actions { display: flex; gap: 8px; margin: 0 0 10px; }
.menu-actions .primary, .menu-actions .ghost { flex: 1; height: 40px; }
.menu-title { margin: 4px 0 8px; font-size: 13px; color: var(--fg-dim); font-weight: 600; }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet-actions .ghost, .sheet-actions .primary { width: auto; flex: 1 1 120px; white-space: nowrap; }

/* ---------- 手机设置 / 动作键 / 发送侧（借鉴 tranvoice 移动端） ---------- */
.pref-list { list-style: none; margin: 4px 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.pref-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px; border-radius: 10px; background: var(--card, rgba(255,255,255,.04)); font-size: 13.5px; }
.pref-toggle { min-width: 74px; min-height: 34px; padding: 6px 10px; border-radius: 9px; border: 1px solid var(--line, rgba(255,255,255,.12)); background: transparent; color: inherit; font-size: 12.5px; }
.pref-toggle[aria-checked="true"] { border-color: #3b82f6; color: #93c5fd; }
.ghost.danger { color: #f87171; border-color: rgba(248,113,113,.35); }

.action-row { display: flex; gap: 8px; padding: 0 12px 6px; }
.action-row[hidden] { display: none; }
.action-row button { flex: 1; min-height: 40px; font-size: 13px; }

/* 发送按钮在左：textarea 先出、按钮在后，用 order 调整 */
.composer.send-left #send { order: -1; }
.composer.send-left #text { order: 0; }

/* iOS 聚焦不缩放：输入框 ≥16px */
textarea#text, #injectText, input.field { font-size: 16px; }

/* 历史列表滚动不带动外层 */
.log { overscroll-behavior: contain; }
.remote-tabs{display:flex;gap:4px;padding:4px;margin:8px 14px;background:#152338;border-radius:14px}.remote-tabs button,.remote-keys button{flex:1;min-height:44px;border:0;border-radius:10px;background:transparent;color:#b6c6dc;font:inherit}.remote-tabs button[aria-pressed=true]{color:white;background:#26465e}.remote-home{overflow:auto;flex:1;padding:8px 14px max(16px,env(safe-area-inset-bottom));scroll-padding-bottom:12px}.remote-home .sheet-card{position:static;box-sizing:border-box;width:100%;max-height:none;margin:auto;padding:16px;background:#132237;border-radius:18px}.remote-home h2{margin:6px 0 14px}.remote-home small{color:#78daca}.remote-home .target,.remote-keys{display:flex;align-items:center;gap:8px;justify-content:space-between}.remote-home .target span{min-width:0;overflow-wrap:anywhere}.remote-home textarea{width:100%;box-sizing:border-box;font-size:16px;min-height:96px}.remote-home #injectSend{width:100%;min-height:48px}.remote-keys button{background:#24374f}.remote-home details{margin:16px 0}.remote-tabs[hidden],.remote-home[hidden],body[data-view=remote] :is(#log,.composer,#actionRow){display:none!important}
.remote-home #targetRefresh{flex:0 0 44px;width:44px;height:44px;min-height:44px;padding:0;font-size:22px;white-space:nowrap}
.remote-home .target{margin:10px 0 14px}
.remote-home .sheet-card .field{resize:vertical}
.bar { gap: 3px; padding-block: calc(max(env(safe-area-inset-top, 0px), var(--sab-top, 0px)) + 4px) 4px; }
.brandbar > .ghost { flex: 0 0 40px; height: 40px; display: grid; place-items: center; padding: 0; line-height: 1; }
.brandbar .chip { flex: none; }
.machinebar .machine { min-width: 40px; min-height: 40px; max-width: 48%; }
.machinebar .remote-tabs { flex: none; margin: 0 0 0 auto; padding: 2px; gap: 1px; }
.remote-tabs button { flex: auto; min-width: 46px; min-height: 40px; padding: 0 8px; white-space: nowrap; }
#menu .menu-actions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
#menu .menu-actions button { display: grid; grid-template-columns: 26px minmax(0,1fr); align-items: center; gap: 9px; min-height: 58px; padding: 8px 10px; text-align: left; }
#menu .menu-actions button > span { display: grid; place-items: center; width: 26px; height: 26px; color: #92cdda; font-size: 20px; line-height: 1; }
#menu .menu-actions b { font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
#menu .menu-actions small { display: block; color: var(--fg-dim); font-weight: 400; }
.remote-home #targetName { min-width: 0; overflow-wrap: anywhere; }
.remote-home .target { margin: 4px 0 8px; }
.remote-home summary { display: list-item; align-content: center; min-height: 40px; }
#injectRecent button { width: 100%; min-height: 40px; display: flex; align-items: center; gap: 8px; text-align: left; }
#injectRecent button span { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-actions .bubble-act { min-width: 40px; min-height: 40px; padding: 4px 8px; }
.msg-wrap.user .msg-actions { opacity: 1; }
#menu #closeMenu { min-height: 40px; height: auto; padding-block: 7px; }
