:root {
  --bg: #0b0d12;
  --panel: #141822;
  --panel-2: #1b2030;
  --line: #262c3d;
  --fg: #e8ecf4;
  --dim: #8b94a8;
  --accent: #4c8dff;
  --high: #ff5c5c;
  --med: #ffb020;
  --low: #6b7690;
  --ok: #37d399;
  --radius: 12px;
}

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

html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  overscroll-behavior-y: none;
  /* 关键：diff 里有超长行，必须在这里截住横向溢出，
     否则 body 被撑宽、标签与按钮被切掉（实测踩过这个 bug）。 */
  max-width: 100vw;
  overflow-x: hidden;
}

#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: rgba(11,13,18,.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
#title { flex: 1; min-width: 0; font-weight: 650; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  background: none; border: none; color: var(--fg); font-size: 22px;
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer; flex: none;
}
.icon-btn:active { background: var(--panel-2); }

/* min-width:0 让 main 能被内容收缩，而不是被长行撑开 */
main { padding: 12px 12px calc(env(safe-area-inset-bottom) + 90px); min-width: 0; max-width: 100%; }
.loading { color: var(--dim); text-align: center; padding: 40px 0; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px; margin-bottom: 10px;
  min-width: 0; overflow-wrap: anywhere;
}
.card h3 { margin: 0 0 6px; font-size: 15px; font-weight: 620; line-height: 1.35; }

.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; min-width: 0; }
.tag {
  font-size: 11px; padding: 3px 7px; border-radius: 6px;
  background: var(--panel-2); color: var(--dim); border: 1px solid var(--line);
  white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.tag.author { color: #9ec1ff; }
.tag.reviewer { color: #ffd08a; }
.tag.risk-high { color: var(--high); border-color: #4a2222; background: #2a1618; }
.tag.risk-medium { color: var(--med); border-color: #4a3a1a; background: #2a2316; }
.tag.risk-low { color: var(--ok); border-color: #1c4436; background: #14261f; }
.tag.state { color: var(--accent); border-color: #23405f; background: #16202e; }
.tag.state-closed_pass { color: var(--ok); border-color: #1c4436; background: #14261f; }
.tag.state-await_decision { color: var(--med); border-color: #4a3a1a; background: #2a2316; }

.stat { display: flex; flex-wrap: wrap; gap: 10px; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--dim); }
.stat .add { color: var(--ok); }
.stat .del { color: var(--high); }

.btn {
  display: block; width: 100%; padding: 13px; margin-top: 10px;
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  font-size: 15px; font-weight: 620; cursor: pointer;
}
.btn:active { filter: brightness(.88); }
.btn:disabled { opacity: .45; }
.btn.ghost { background: var(--panel-2); color: var(--fg); border: 1px solid var(--line); }
.btn.danger { background: #a33; }
.btn.small { padding: 9px; font-size: 14px; margin-top: 8px; }

.row { display: flex; gap: 8px; min-width: 0; }
.row .btn { flex: 1; min-width: 0; }

.section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--dim); margin: 18px 4px 8px;
}

/* ---- diff ---- */
.diff {
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #0d1017; border: 1px solid var(--line); border-radius: 10px;
  overflow-x: auto; margin-top: 10px; -webkit-overflow-scrolling: touch;
  /* 必须显式限宽 + min-width:0，否则超长行会把外层撑开 */
  width: 100%; max-width: 100%; min-width: 0;
}
.diff .hline { padding: 1px 10px; white-space: pre; }
.diff .add { background: #10251c; color: #9ce8c4; }
.diff .del { background: #2a1618; color: #ffb3b3; }
.diff .hunk { background: #16202e; color: #7fa8e0; }
.diff .ctx { color: #93a0b8; }
.diff .filehead { background: var(--panel-2); color: #cdd6e6; font-weight: 600; padding: 6px 10px; }

/* ---- findings ---- */
.finding {
  background: var(--panel); border: 1px solid var(--line); border-left-width: 3px;
  border-radius: var(--radius); padding: 12px; margin-bottom: 9px;
  min-width: 0; overflow-wrap: anywhere;
}
.finding.sev-high { border-left-color: var(--high); }
.finding.sev-medium { border-left-color: var(--med); }
.finding.sev-low { border-left-color: var(--low); }
.finding.accepted { opacity: .95; box-shadow: inset 0 0 0 1px #1c4436; }
.finding.rejected { opacity: .42; }

.finding .where {
  font: 12px ui-monospace, Menlo, monospace; color: #9ec1ff;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-bottom: 6px;
  min-width: 0;
}
.finding .msg { font-size: 14px; overflow-wrap: anywhere; }
.finding .fix {
  margin-top: 8px; padding: 9px; background: #0d1017; border-radius: 8px;
  font: 12px/1.5 ui-monospace, Menlo, monospace; color: #9ce8c4; white-space: pre-wrap;
  border: 1px solid var(--line); overflow-wrap: anywhere; min-width: 0;
}
.finding .fix-label { font-size: 11px; color: var(--dim); margin-top: 9px; text-transform: uppercase; letter-spacing: .05em; }
.finding .flags { margin-top: 7px; }

.pill { font-size: 10px; padding: 2px 6px; border-radius: 5px; background: var(--panel-2); color: var(--dim); margin-right: 5px; border: 1px solid var(--line); }
.pill.warn { color: var(--med); border-color: #4a3a1a; }

/* ---- policy trace ---- */
.trace { font-size: 12px; }
.trace .t { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.trace .t:last-child { border-bottom: none; }
.trace .dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 6px; flex: none; }
.trace .dot.pass { background: var(--ok); }
.trace .dot.warn { background: var(--med); }
.trace .dot.block { background: var(--high); }
.trace .name { font-weight: 600; }
.trace .why { color: var(--dim); font-size: 11px; }

/* ---- sticky action bar ---- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  background: rgba(11,13,18,.94); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex; gap: 8px;
}
.actionbar .btn { margin-top: 0; }

/* ---- modal ---- */
.sheet-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40;
  display: flex; align-items: flex-end;
}
.sheet {
  width: 100%; max-height: 86vh; overflow-y: auto;
  background: var(--panel); border-radius: 18px 18px 0 0;
  padding: 16px 14px calc(env(safe-area-inset-bottom) + 16px);
  border-top: 1px solid var(--line);
}
.sheet h2 { margin: 0 0 4px; font-size: 17px; }
.sheet .sub { color: var(--dim); font-size: 12px; margin-bottom: 12px; }

.reviewer-opt {
  display: flex; align-items: center; gap: 10px; padding: 12px;
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px;
  background: var(--panel-2); cursor: pointer;
}
.reviewer-opt.selected { border-color: var(--accent); background: #16202e; }
.reviewer-opt.blocked { opacity: .38; }
.reviewer-opt .rn { flex: 1; font-size: 13px; word-break: break-all; }
.reviewer-opt .rv { font-size: 11px; color: var(--dim); }

.empty { text-align: center; color: var(--dim); padding: 40px 20px; }
.empty .big { font-size: 34px; margin-bottom: 10px; }
.hint { font-size: 12px; color: var(--dim); margin-top: 8px; line-height: 1.5; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 96px); z-index: 60;
  background: #232a3c; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 13px; max-width: 86vw; text-align: center; border: 1px solid var(--line);
}
.spinner { display:inline-block; width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 7px;}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- 会话浏览（三层导航）---- */
.tap { cursor: pointer; }
.path {
  font: 11px/1.4 ui-monospace, Menlo, monospace; color: #6b7690;
  margin-top: 6px; word-break: break-all;
}
.dimtext { color: #6b7690; }

/* 对话气泡 */
.turn {
  border-radius: 12px; padding: 10px 12px; margin-bottom: 9px;
  border: 1px solid var(--line); min-width: 0; overflow-wrap: anywhere;
}
.turn.mine { background: #16202e; border-color: #23405f; }
.turn.theirs { background: var(--panel); }
.turn-head {
  font-size: 11px; color: var(--dim); margin-bottom: 6px;
  letter-spacing: .03em;
}
.turn .bubble-text { font-size: 14px; white-space: pre-wrap; }
.turn .file-ref {
  font: 12px ui-monospace, Menlo, monospace; color: #9ec1ff;
  background: #0d1017; padding: 1px 4px; border-radius: 4px;
}
.fold { margin-top: 7px; }
.fold > summary {
  font-size: 12px; color: var(--dim); cursor: pointer;
  padding: 5px 8px; background: var(--panel-2); border-radius: 7px;
  border: 1px solid var(--line); list-style: none;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::before { content: '▸ '; }
.fold[open] > summary::before { content: '▾ '; }
.fold-body {
  margin-top: 6px; padding: 9px; background: #0d1017; border-radius: 8px;
  font-size: 12px; color: #93a0b8; white-space: pre-wrap;
  border: 1px solid var(--line); overflow-wrap: anywhere; max-height: 320px; overflow-y: auto;
}
.fold-body.mono { font-family: ui-monospace, Menlo, monospace; }
