/* styles.css —— 手机优先。深色、单列、拇指可达区集中在底部。
   刻意不用任何 CSS 框架：Capacitor 打包后没有构建步骤，少一层依赖少一处坑。 */

:root {
  --bg: #0f1115;
  --bg2: #161a22;
  --bg3: #1e2430;
  --fg: #e8ecf3;
  --fg-dim: #98a2b3;
  --line: #262d3a;
  --accent: #4f8cff;
  --accent2: #2fbf71;
  --warn: #f0a13a;
  --err: #ef5f5f;
  --me: #2b4a86;
  --peer: #232a36;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }

/**
 * 必须显式声明 [hidden]。
 * 浏览器默认的 `[hidden] { display: none }` 来自 UA 样式表，优先级极低，
 * 任何作者样式里的 `display` 都会把它覆盖掉：本例中 `.sheet { display: flex }`
 * 让 `hidden` 的遮罩层照常显示并**盖住整页**（.sheet 是 position:fixed; inset:0），
 * 于是所有按钮都点不动——排查时表现为"点击完全没反应"。
 * 这类问题在自动化里很难归因，所以这里一次写死，别再靠元素自带的 hidden 语义兜底。
 */
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior-y: none;
}

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

/* ── 顶栏 ─────────────────────────────────────────────── */
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) 10px 8px;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.bar-left { flex: 0 1 auto; min-width: 0; }
.bar-mid { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; gap: 6px; min-width: 0; }
.bar-right { flex: 0 0 auto; display: flex; gap: 4px; }
.selfname {
  font-size: 12px; color: var(--fg-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg3); color: var(--fg);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 10px; font-size: 13px; max-width: 46vw;
}
.chip #peerName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { color: var(--fg-dim); font-size: 10px; }
.mini {
  background: transparent; border: 1px solid var(--line); color: var(--fg);
  border-radius: 8px; padding: 5px 8px; font-size: 15px; line-height: 1;
}
.mini.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-dim); flex: 0 0 auto; }
.dot.on { background: var(--accent2); box-shadow: 0 0 6px var(--accent2); }
.dot.err { background: var(--err); }

/* ── 提示条 ───────────────────────────────────────────── */
.banner {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; font-size: 13px;
  background: #3a2c14; color: #ffd79a; border-bottom: 1px solid #5a4318;
}
.banner.error { background: #3a1a1a; color: #ffb4b4; border-bottom-color: #5c2626; }
.banner span { flex: 1; }
.banner button { border-color: currentColor; color: inherit; }

/* ── 消息区 ───────────────────────────────────────────── */
.chat {
  flex: 1 1 auto; overflow-y: auto; padding: 12px 10px 4px;
  display: flex; flex-direction: column; gap: 8px;
  -webkit-overflow-scrolling: touch;
}
.row { display: flex; }
.row.me { justify-content: flex-end; }
.row.sys { justify-content: center; }
.bubble {
  max-width: 84%; padding: 8px 11px; border-radius: 14px;
  background: var(--peer); white-space: pre-wrap; word-break: break-word;
  border: 1px solid var(--line);
}
.row.me .bubble { background: var(--me); border-color: #3a5c9e; }
.bubble .meta {
  display: block; font-size: 11px; color: #b9c4d6; opacity: .85;
  margin-bottom: 3px;
}
.bubble .body { font-size: 15px; }
.bubble.pending { opacity: .6; }
.bubble.failed { border-color: var(--err); }
.sysmsg {
  font-size: 12px; color: var(--fg-dim); background: var(--bg3);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px;
}
.msg-actions { display: flex; gap: 6px; margin-top: 4px; }
.msg-actions button {
  background: transparent; border: 1px solid var(--line); color: var(--fg-dim);
  border-radius: 6px; font-size: 11px; padding: 2px 6px;
}

/* 空态：从 #chat 里搬出来后要自己撑满并居中（原来是借 #chat 的 flex 居中） */
.empty {
  flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center;
  margin: auto; text-align: center; color: var(--fg-dim); padding: 20px; max-width: 460px;
}
.empty h2 { color: var(--fg); font-size: 17px; margin: 0 0 8px; }
.empty ol { text-align: left; font-size: 14px; line-height: 1.9; padding-left: 20px; }
.empty b { color: var(--fg); }
.empty button { margin-top: 8px; }

/* ── 结构化视图（智能体推来的表格/流水/键值/代码）───────────
   手机窄屏 + 深色主题下的取舍：
   - 表格横向可滚动（不缩字号、不挤压换行），表头吸顶
   - 流水用等宽字体对齐时间戳，级别用左侧色条区分
   - 这些内容来自外部（智能体），渲染时只用 textContent，样式在这里集中管 */
.view {
  margin-top: 6px; border: 1px solid var(--line); border-radius: 10px;
  background: #12161d; overflow: hidden;
}
.view-title { font-size: 12px; color: var(--fg-dim); padding: 7px 10px 0; font-weight: 600; }
.view-note { font-size: 11px; color: var(--fg-dim); padding: 5px 10px 8px; }
.view-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.view-table { border-collapse: collapse; font-size: 12.5px; min-width: 100%; }
.view-table th, .view-table td {
  text-align: left; padding: 6px 10px; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.view-table th { color: var(--fg-dim); font-weight: 600; background: #171c25; }
.view-table tr:last-child td { border-bottom: none; }
.view-table tbody tr:nth-child(even) { background: rgba(255, 255, 255, .02); }
.view-stream { padding: 6px 0; }
.vs-row {
  display: flex; gap: 7px; align-items: baseline;
  padding: 3px 10px; font-size: 12.5px; line-height: 1.5;
  border-left: 3px solid transparent;
}
.vs-ts { color: var(--fg-dim); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px; flex: 0 0 auto; }
.vs-lv {
  font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  padding: 0 5px; border-radius: 4px; background: var(--bg3); color: var(--fg-dim); flex: 0 0 auto;
}
.vs-text { flex: 1 1 auto; word-break: break-word; }
.vs-row.lv-info { border-left-color: var(--accent); }
.vs-row.lv-warn { border-left-color: var(--warn); }
.vs-row.lv-error { border-left-color: var(--err); }
.vs-row.lv-error .vs-lv { background: #3a1a1a; color: #ffb4b4; }
.vs-row.lv-warn .vs-lv { background: #3a2c14; color: #ffd79a; }
.view-kv { display: grid; grid-template-columns: minmax(84px, auto) 1fr; font-size: 12.5px; }
.vk-k { color: var(--fg-dim); padding: 6px 10px; border-bottom: 1px solid var(--line); }
.vk-v { padding: 6px 10px; border-bottom: 1px solid var(--line); word-break: break-word; }
.view-code {
  margin: 0; padding: 9px 11px; overflow-x: auto;
  font: 12px/1.6 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre; color: #d7e2f0; background: #0e1219;
}

/* ── 输入区 ───────────────────────────────────────────── */
.composer {
  border-top: 1px solid var(--line); background: var(--bg2);
  padding: 8px 10px calc(8px + var(--safe-b));
}
.composer-row {
  display: flex; align-items: flex-end; gap: 6px;
}
textarea#input {
  /* flex 权重给足：输入框是这块区域的主体，按钮只是附属 */
  flex: 1 1 auto; min-width: 0; resize: none;
  /* 至少两行可视，避免"打完字看不见自己打了什么" */
  min-height: 46px; max-height: 40vh;
  background: var(--bg3); color: var(--fg);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 11px 13px; font: inherit; font-size: 16px; line-height: 1.45;
}
textarea#input:focus { outline: none; border-color: var(--accent); }
textarea#input::placeholder { color: #6b7484; }
.round {
  flex: 0 0 auto; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg3); color: var(--fg);
  display: grid; place-items: center;
}
/* 麦克风：主操作，给足触控面积 */
.round.mic { width: 42px; height: 42px; font-size: 18px; }
/* 发送：小一圈、默认低调（之前 40×40 + 常亮蓝色，比输入框还抢眼，
   用户反馈"发送键很大却看不到自己打的字"，所以把视觉重量还给输入框） */
.round.send { width: 34px; height: 34px; font-size: 15px; margin-bottom: 4px; opacity: .55; }
.round.send.ready { opacity: 1; background: var(--accent); border-color: var(--accent); color: #fff; }
/* 录音时出现的放弃按钮：明显但克制 */
.round.danger { width: 34px; height: 34px; font-size: 15px; margin-bottom: 4px; color: var(--err); border-color: #5c2626; }
.round.listening { background: var(--err); border-color: var(--err); color: #fff; animation: pulse 1.1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(239,95,95,.6); } 50% { box-shadow: 0 0 0 10px rgba(239,95,95,0); } }
.composer-note { font-size: 11px; color: var(--fg-dim); margin-top: 5px; min-height: 14px; }
.interim {
  font-size: 13px; color: var(--accent); background: var(--bg3);
  border: 1px dashed var(--accent); border-radius: 10px;
  padding: 6px 10px; margin-bottom: 7px;
}
/* 录音音量条：只做「有没有在说」的判断，不做波形，省电 */
.level-wrap {
  height: 6px; background: var(--bg3); border-radius: 3px;
  overflow: hidden; margin-bottom: 7px; border: 1px solid var(--line);
}
.level-bar {
  height: 100%; width: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent));
  transform: scaleX(0); transform-origin: left center;
  transition: transform 80ms linear;
}

/* ── 弹层 ─────────────────────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.sheet-card {
  position: relative; width: 100%; max-height: 86dvh; overflow: hidden;
  background: var(--bg2); border-top-left-radius: 16px; border-top-right-radius: 16px;
  border-top: 1px solid var(--line); display: flex; flex-direction: column;
  padding-bottom: var(--safe-b);
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.sheet-head h3 { margin: 0; font-size: 15px; }
.sheet-body { padding: 12px 14px 18px; overflow-y: auto; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--fg-dim); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg3); color: var(--fg);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font: inherit; font-size: 15px;
}
.field .tip { font-size: 11px; color: var(--fg-dim); margin-top: 5px; line-height: 1.5; }
.field.row-inline { display: flex; align-items: center; gap: 10px; }
.field.row-inline input[type="checkbox"] { width: 20px; height: 20px; flex: 0 0 auto; }
.field.row-inline label { margin: 0; font-size: 14px; color: var(--fg); }

button.primary {
  width: 100%; background: var(--accent); color: #fff; border: none;
  border-radius: 10px; padding: 12px; font-size: 15px; font-weight: 600;
}
button.ghost {
  width: 100%; background: transparent; color: var(--fg);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px; font-size: 14px;
}
button.danger { color: var(--err); border-color: #5c2626; }
.row-btns { display: flex; gap: 8px; }

.codebox {
  font-size: 30px; letter-spacing: 8px; text-align: center; font-weight: 700;
  background: var(--bg3); border: 1px solid var(--accent); border-radius: 12px;
  padding: 14px; margin: 8px 0; color: var(--accent);
  user-select: all;
}
.steps { font-size: 13px; color: var(--fg-dim); line-height: 1.8; padding-left: 18px; margin: 6px 0 0; }
.peer-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 4px;
  border-bottom: 1px solid var(--line);
}
.peer-item .nm { flex: 1; }
.peer-item .sub { font-size: 11px; color: var(--fg-dim); }
.kv { font-size: 13px; color: var(--fg-dim); line-height: 1.9; }
.kv b { color: var(--fg); }
/* 自检输出：保留换行与缩进，等宽字体便于对齐阅读 */
.diag {
  white-space: pre-wrap; word-break: break-word;
  font: 12.5px/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--bg3); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin: 0; color: var(--fg);
}

/* ── Toast ────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(78px + var(--safe-b));
  transform: translateX(-50%); z-index: 90;
  background: #2b3340; color: var(--fg); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 14px; font-size: 13px; max-width: 90vw;
  box-shadow: 0 6px 20px rgba(0,0,0,.45);
}
.toast.error { border-color: var(--err); color: #ffc9c9; }

@media (min-width: 720px) {
  #app { max-width: 780px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .sheet-card { max-width: 620px; margin: 0 auto; border-radius: 16px; }
  .sheet { align-items: center; }
}
