/* Watchtower PWA — conversation-first phone UI (no build step). */
:root {
  --bg: #0f172a; --bg2: #1e293b; --card: #1e293b; --line: #334155;
  --fg: #f1f5f9; --muted: #94a3b8; --accent: #38bdf8; --accent2: #818cf8;
  --ok: #34d399; --warn: #fbbf24; --err: #f87171; --info: #38bdf8;
  --radius: 14px; --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; }
/* 卡片/按钮形 <a> 的根因修复：inline <a> 带 border/背景会按行盒断裂成"左侧圆角残片"
   （Owner 真机截图的 mobile layout FAIL），且默认链接色/下划线会泄漏进卡片。 */
a { color: inherit; text-decoration: none; }
a.card { display: block; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.empty { text-align: center; padding: 46px 0; }
#app { height: 100%; }
.screen { height: 100%; overflow-y: auto; }

/* ----- Login ----- */
#view-login { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; text-align: center; padding: 32px 20px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; }
.login-card .logo { font-size: 56px; color: var(--accent); margin-bottom: 4px; }
.login-card h1 { margin: 8px 0 2px; font-size: 26px; }
#login-form { margin-top: 20px; display: flex; flex-direction: column; gap: 12px; }
input, textarea, select {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--fg); font-size: 15px;
}
.err { color: var(--err); margin-top: 10px; font-size: 13px; }

/* ----- Shell ----- */
#view-shell { display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 14px 10px;
  border-bottom: 1px solid var(--line); background: rgba(15,23,42,.95);
  position: sticky; top: 0; z-index: 5; flex: none;
}
.topbar .title { flex: 1; font-weight: 600; font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { min-width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg2); color: var(--fg); font-size: 22px; line-height: 1; flex: none; }
.conn { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.conn.online { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.conn.reconnecting { background: var(--warn); animation: pulse 1s infinite; }
.conn.offline { background: var(--err); }
@keyframes pulse { 50% { opacity: .4; } }

.tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--bg); flex: none; }
.tab { flex: 1; padding: 12px; background: none; border: none; color: var(--muted); font-size: 15px; font-weight: 600; border-bottom: 2px solid transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.content { padding: 14px; overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; }

/* ----- Cards / lists ----- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row > * { min-width: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.err { background: var(--err); }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; flex: none; }
.badge.running { background: rgba(56,189,248,.18); color: var(--info); }
.badge.waiting { background: rgba(251,191,36,.2); color: var(--warn); }
.badge.permission { background: rgba(251,146,60,.22); color: #fdba74; }
.badge.question { background: rgba(168,85,247,.2); color: #d8b4fe; }
.badge.error { background: rgba(248,113,113,.2); color: var(--err); }
.badge.finished, .badge.done, .badge.merged, .badge.pr { background: rgba(52,211,153,.16); color: var(--ok); }
.badge.idle { background: rgba(148,163,184,.16); color: var(--muted); }
.badge.offline { background: rgba(100,116,139,.2); color: #94a3b8; }
.badge.stale { background: rgba(251,191,36,.16); color: var(--warn); }
.meta { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; min-width: 0; }
.title-line { font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.section-title { margin: 16px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.agent-sec { margin-top: 18px; }

/* live 活动行 */
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; animation: pulse 1.2s infinite; }
.act { display: block; font-size: 12.5px; color: var(--fg); overflow-wrap: anywhere; min-width: 0; }
.act-label { color: var(--fg); }
.snippet { margin-top: 4px; }
.ws-line, .agent-line { display: flex; align-items: center; gap: 6px; padding: 3px 0; flex-wrap: wrap; min-width: 0; }
.ws-line .ws-name, .agent-line .agent-name { color: var(--muted); font-size: 12px; flex: none; max-width: 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-line .act, .agent-line .act { display: inline; flex: 1; min-width: 0; }
.ws-summary { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; }
/* Agent chips: on the home screen an agent is a navigation target, never plain text in a row. */
.ws-entry { border-bottom: 1px solid rgba(51,65,85,.5); }
.ws-entry:last-child { border-bottom: none; }
.agent-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 0 8px; }
a.agent-chip { display: inline-flex; align-items: center; gap: 6px; min-width: 0; padding: 3px 9px;
  border: 1px solid var(--line); border-radius: 999px; color: inherit; text-decoration: none; font-size: 12px; }
a.agent-chip .chip-name { font-weight: 600; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.agent-chip .chip-state { color: var(--muted); }
a.agent-chip .chip-state.ok { color: #34d399; }
a.agent-chip .chip-state.off { color: var(--muted); }
.agent-lines { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; }
.session-card.is-active { border-color: rgba(56,189,248,.35); }

/* ----- Buttons ----- */
.btn { border: 1px solid var(--line); background: var(--bg2); color: var(--fg); padding: 11px 16px; border-radius: 11px; font-size: 15px; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--accent); color: #06283f; border-color: var(--accent); }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: rgba(248,113,113,.15); color: var(--err); border-color: rgba(248,113,113,.3); }
.btn.ok { background: rgba(52,211,153,.15); color: var(--ok); border-color: rgba(52,211,153,.3); }
.btn:disabled { opacity: .5; }
.btnrow { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.btnrow .btn { flex: 1; min-width: 90px; }

/* ----- Conversation timeline ----- */
.head-card .statehead { display: flex; align-items: center; gap: 10px; }
.conversation { padding: 4px 0 8px; }
.conv-empty { text-align: center; padding: 30px 0; }
.msg { display: flex; gap: 8px; margin: 10px 0; align-items: flex-start; min-width: 0; }
.msg .who { flex: none; font-weight: 700; font-size: 12px; color: var(--accent2); padding-top: 4px; min-width: 34px; }
.msg.human .who { color: var(--ok); }
.msg .bubble { flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 14.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.msg.human .bubble { border-color: rgba(52,211,153,.3); background: rgba(52,211,153,.06); }
.msg.streaming .bubble { border-color: rgba(129,140,248,.45); }
.typing { display: inline-flex; gap: 4px; margin-left: 8px; vertical-align: middle; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent2); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 70%, 100% { opacity: .25; } 35% { opacity: 1; } }

/* 工具卡：默认折叠单行（AoE compact-activity 语义），running 常展开 */
details.sysinject { background: transparent; border: 1px dashed var(--line); border-radius: 8px; padding: 4px 10px; margin: 4px 0 4px 42px; font-size: 11.5px; max-width: calc(100% - 42px); }
details.sysinject summary { color: var(--muted); cursor: pointer; list-style: none; }
details.sysinject summary::-webkit-details-marker { display: none; }
details.toolcall, details.reasoning, details.plan-card { background: #0b1120; border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; margin: 6px 0 6px 42px; font-size: 12.5px; max-width: calc(100% - 42px); }
details.toolcall summary, details.reasoning summary, details.plan-card summary { cursor: pointer; color: var(--muted); font-weight: 600; list-style: none; display: flex; align-items: center; gap: 6px; min-width: 0; }
details.toolcall summary::-webkit-details-marker, details.reasoning summary::-webkit-details-marker, details.plan-card summary::-webkit-details-marker { display: none; }
details.toolcall summary::before, details.reasoning summary::before, details.plan-card summary::before { content: "▸"; color: var(--muted); flex: none; }
details[open].toolcall summary::before, details[open].reasoning summary::before, details[open].plan-card summary::before { content: "▾"; }
.tname { color: var(--warn); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tstate { flex: none; }
.tstate.ok { color: var(--ok); } .tstate.error { color: var(--err); } .tstate.running { color: var(--info); animation: pulse 1s infinite; }
.tsnip { color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
details.toolcall pre, details.reasoning pre, details.plan-card pre, pre.output { margin: 8px 0 0; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; max-height: 240px; overflow-y: auto; font-family: ui-monospace, Consolas, monospace; font-size: 12px; line-height: 1.5; }
details.reasoning summary { color: #a5b4fc; }
details.plan-card { border-color: rgba(251,191,36,.35); }
details.plan-card summary { color: var(--warn); }

/* 审批 */
.approval { margin: 8px 0; font-size: 13px; min-width: 0; }
.approval.pending { background: rgba(251,146,60,.08); border: 1px solid rgba(251,146,60,.4); border-radius: 12px; padding: 10px 12px; }
.approval.pending .ap-head { font-weight: 700; color: #fdba74; }
.approval.resolved { color: var(--muted); margin-left: 42px; }
.approval-reason { margin: 4px 0; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.shelf-card { border-left: 3px solid var(--warn); }
.ap-actions .btnrow { margin-top: 8px; }

/* 状态条 */
.restore-note { background: rgba(148,163,184,.08); border: 1px dashed var(--line); color: var(--muted); font-size: 12.5px; border-radius: 10px; padding: 8px 12px; margin: 8px 0; }
.capnote { color: var(--muted); font-size: 13px; }
.idmeta { margin-top: 8px; font-size: 12px; }
.idmeta summary { cursor: pointer; color: var(--muted); list-style: none; }
.idmeta summary::-webkit-details-marker { display: none; }
.idmeta div { margin-top: 3px; }

/* 输入 */
.toolbar { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0 calc(10px + var(--safe-b)); }
.composer { display: flex; gap: 8px; }
.composer input { flex: 1; min-width: 0; }

/* 文件 */
.filelist .fentry { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); min-width: 0; }
.fentry .nm { flex: 1; word-break: break-all; overflow-wrap: anywhere; min-width: 0; }
.fentry .btn { flex: none; }
.output { background: #020617; border: 1px solid var(--line); border-radius: 10px; padding: 10px; max-height: 50vh; overflow-y: auto; }

/* ----- Toast ----- */
.toast { position: fixed; left: 50%; bottom: calc(40px + var(--safe-b)); transform: translateX(-50%); background: #0b1120; border: 1px solid var(--line); color: var(--fg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90%; z-index: 20; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.toast.err { border-color: var(--err); color: var(--err); }
.toast.ok { border-color: var(--ok); color: var(--ok); }


/* ----- 2026-09-18 rework: hierarchy + attention ----- */
.col { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.spacer { flex: 1; }
.pad { padding: 8px 2px; }
.attention-title { color: var(--warn); }
.badge.attention { background: rgba(251,146,60,.22); color: #fdba74; animation: pulse 1.6s infinite; }
.badge.done { background: rgba(52,211,153,.16); color: var(--ok); }
.attention-card { display: block; border-left: 3px solid var(--warn); background: linear-gradient(180deg, rgba(251,146,60,.10), rgba(251,146,60,.03)); }
.attention-card.big { border-left-width: 4px; }
.attention-card .pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 0 rgba(251,146,60,.6); animation: ring 1.8s infinite; flex: none; }
@keyframes ring { 70% { box-shadow: 0 0 0 10px rgba(251,146,60,0); } 100% { box-shadow: 0 0 0 0 rgba(251,146,60,0); } }
.attention-detail { margin-top: 6px; font-size: 13px; color: #fdba74; overflow-wrap: anywhere; }
.attention-detail.small { font-size: 12px; color: var(--warn); }
.machine-card { padding: 12px 14px; }
.machine-card > a.row { color: inherit; }
.ws-line, .ws-head { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(51,65,85,.5); min-width: 0; }
.ws-line:last-child, .ws-head:last-child { border-bottom: none; }
.ws-summary { margin-top: 6px; }
.ws-card { padding: 12px 14px; }
.agent-lines { margin-top: 6px; border-top: 1px solid var(--line); padding-top: 6px; }
.agent-line { display: flex; align-items: center; gap: 8px; padding: 6px 0; flex-wrap: wrap; min-width: 0; }
.agent-line .agent-name, .agent-head .agent-name { color: var(--fg); font-size: 13.5px; font-weight: 600; }
.agent-block { margin-bottom: 6px; }
.agent-head { display: flex; align-items: center; gap: 8px; margin: 16px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.rt-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.rt-item { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); }
.rt-item i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.rt-item.ok i { background: var(--ok); } .rt-item.off i { background: var(--error, #6b7280); background: #64748b; } .rt-item.unknown i { background: var(--warn); }
.rt { margin-left: 4px; }
.hist-toggle { margin: 6px 0 10px; }
.session-card.is-live { border-color: rgba(56,189,248,.35); }
.session-card.is-attention { border-color: rgba(251,146,60,.45); }

/* follow-live affordance */
.jump-latest {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + var(--safe-b)); z-index: 12;
  background: rgba(30,41,59,.97); color: var(--accent); border: 1px solid var(--line);
  border-radius: 999px; padding: 9px 16px; font-size: 13px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.45); backdrop-filter: blur(6px);
}
.jump-latest.hidden { display: none; }
.ap-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.conversation > .blk { min-width: 0; }

/* 窄屏（360px 级）收缩 */
@media (max-width: 380px) {
  .msg .who { min-width: 30px; font-size: 11px; }
  details.toolcall, details.reasoning, details.plan-card { margin-left: 38px; max-width: calc(100% - 38px); }
  .approval.resolved { margin-left: 38px; }
  .btnrow .btn { min-width: 80px; padding: 10px 10px; }
}